0

I have the classic Multiple Servers 1 IP trouble Except I am using ESXi (s1) to host to Server VMs (VM1, VM2). What I'm trying to accomplish is this:

When Someone Goes to example.com they get S1-VM1 which hosts my blog, website and all that jazz.

but when they go to code.example.com they get S1-VM2 which will host ONLY hot gitlab for my code.

Variables:

  1. VM1 is CentOS based, VM2 is Ubuntu Server
  2. My Router with the Ext IP is handling DHCP

Please let me know where I can read/go/ to get started with this as I am utterly unsure of where to begin doing something like this. Could this be as simple as a reverse proxy with CentOSs implementation of Apache? Perhaps something similar to This?

UPDATE: So I have this partially figured out. The below configuration seems to redirect ALL traffic from example.com to https://sub.example.com. if anyone would is willing to look this over and give me some feedback as to why this might be happening and suggest an adjustment I would be stoked as it's the holidays and I have all the time in the world to play with my servers.

<VirtualHost 192.0.2.1:80>
  ServerName sub.example.com
  Redirect permanent / http://sub.example.com/
</VirtualHost>
<VirtualHost 192.0.2.1:443>
  ServerName sub.example.com
  ErrorLog logs/sub.example.com-error_log
  CustomLog logs/sub.example.com-access_log combined
  SSLEngine On
  SSLCertificateFile /etc/httpd/conf.d/ssl/server.crt
  SSLCertificateKeyFile /etc/httpd/conf.d/ssl/server.key
  #SSLCACertificateFile /etc/httpd/conf.d/ssl/rapidssl.crt
  ProxyRequests Off
  ProxyPreserveHost On
  ProxyPass / http://192.168.1.252/
  ProxyPassReverse / http://192.168.1.252/
</VirtualHost>

**UPDATE2:**So The Errors I am having at this point are related to SSL. I have amended the above configuration to the following:

<VirtualHost 192.0.2.1:80>
  ServerName sub.example.com
  Redirect permanent / http://sub.example.com/
  ProxyPass / http://192.168.1.252
  ProxyPassReverse / http://192.168.1.252
</VirtualHost>
<VirtualHost 192.168.1.252:443>
  ServerName sub.example.com
  ErrorLog logs/sub.example.com-error_log
  CustomLog logs/sub.example.com-access_log combined
  SSLEngine off
  SSLCertificateFile /etc/httpd/conf.d/ssl/server.crt
  SSLCertificateKeyFile /etc/httpd/conf.d/ssl/server.key
  #SSLCACertificateFile /etc/httpd/conf.d/ssl/rapidssl.crt
  ProxyRequests Off
  ProxyPreserveHost On
  ProxyPass / http://192.168.1.252/
  ProxyPassReverse / http://192.168.1.252/
</VirtualHost>

I did this based on a hunch from the logs that stated, in no specific terms, There was no match RSA key or something. with the config above the public facing server is is redirecting requests for sub.example.com to the internal servers HTTP website. but now that jacks everything else up for example when I do something like example.com/blog there is a proxy error:

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /blog.

Reason: DNS lookup failure for: 192.168.1.252blog 

Any thoughts?

  • Can you give me any insight on how to go about doing this? The instructional sites I've found for this make no sense. – user502301 Dec 11 '15 at 3:12
  • Sadly no. it actually looks like I'm either being bruteforced or DDoSd Checking out /var/log/secure I have 4106 failed log in attempts Claiming " Dec 8 11:11:42 localhost sshd[2055]: reverse mapping checking getaddrinfo for 84.204.25.185.servereasy.it [185.25.204.84] failed - POSSIBLE BREAK-IN ATTEMPT!" – user502301 Dec 12 '15 at 5:09
  • Do you have reddit sir? – user502301 Dec 12 '15 at 21:27
  • @ekaj yeah check out the update. I have posted my working configuration if you can give me some guidance on why it might not be behaving as expected. – user502301 Dec 27 '15 at 20:25
  • No Joy, Changing it to *:80/443 Causes a redirect error (redirect in a way that wont be fulfilled) restoring the original config and reconfiguring for the internal server's new IP (By choice not DHCP) I get the following errors in the logs [Sun Dec 27 17:52:25.063518 2015] [ssl:warn] [pid 26917] AH01909: RSA certificate configured for sub.domain.com:443 does NOT include an ID which matches the server name – user502301 Dec 27 '15 at 22:57
0

So for this you're going to want to use a reverse proxy. A reverse proxy lets you access multiple servers behind one external IP. Make sure your CNAME record is set up correctly with the host as code and value as example.com.

I followed this guide, loosely. My OS was CentOS 7.1.

First, make sure Apache/httpd is installed. If it is already, you can skip this step.

sudo yum install httpd

Do the basic configuration for your main server then continue to enable access to your other servers. We need to edit the httpd.conf file to do the redirects:

vi /etc/httpd/conf/httpd.conf

Add this in to do the actual work:

<VirtualHost *:80>
        ServerName code.example.com
        ProxyPass / http://S1-VM2:80/
        ProxyPassReverse / http://S1-VM2:80/
</VirtualHost>

Then we need to restart the Apache service: service httpd restart

Lastly you need to set up your Ubuntu web server. For the ServerName in /etc/apache2/sites-available/default put code.example.com then restart the web server by running service apache2 restart.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.