0

I have two web servers behind a router: 1 line of business web app/site (Windows) and 1 LAMP/web dev server with multiple sites/projects (apache with vhosts, own domains, etc.). So far to access web dev projects publicly I've been using different ports for each vhost on the linux server as port 80 forwards to the Windows server (it takes precedence). Now I prefer to use my domains and sub-domains to access my web dev projects publicly (instead of hard to remember port numbers)... how do I set it up so I can access all web sites on both servers over port 80 (and port 443... I'm adding SSL)?

3

Set up a reverse proxy server (listening on ports 80 and 443) between your router and the other two servers, and direct the traffic by hostname from the proxy server to the other two (or more) servers. Note: by doing this you will also be able to purchase a single wildcard or SAN capable certificate to handle ALL of your secure sites.

You have not given enough information about your specific configuration to explain exactly how to do this, but this site and others are full of information regarding setting up and configuring reverse proxies. (Even if it were the case that you had provided enough information, however, such a broad "how do I ..." question would probably be off topic at ServerFault.)

In any case, you will be able to direct any incoming site to any backend server, regardless of what assortment of technologies are used to set up the backend servers (Apache, nginx, IIS, etc.), and the "redirection" (i.e., reverse proxying) can be based only on the hostname in the request (whether by domain name, subdomain name, or even specific directories or files). In fact, you can even send traffic to external sites, but is you do, of course, you will need to ensure that that you appropriately handle security (i.e., ensuring https, etc.) for the traffic outside of your firewall. In other words, the technology does everything that you want it do, just like you want it to do!

The reverse proxy can be implemented as a specifically configured Apache, IIS, nginx or other "web server" and also there are many "server" technologies that are specifically adapted for this (e.g., haproxy).

Given where you are in this process, you should take this guidance and learn more about the technologies in general. In other words, you should not expect that this particular question will lead to someone (1) selecting the right implementation and (2) telling you how to set it up and configure it for your particular problem.

Once you get to that point, you will be able to come back to ServerFault any time for specific questions regarding specific problems for which you have unsuccessfully attempted to apply specific solutions.

Steps for "solving" your problem:

  1. identify an appropriate solution (COMPLETED: a reverse proxy is what you need)
  2. identify and evaluate possible implementations (WELL ON THE WAY: many have been identified for you here, and searching this site and others for reverse proxies will give you an enormous amount of information)
  3. select a technology to implement the solution
  4. set up and configure selected technology (ServerFault is here for you, just bring specific questions regarding problems that you have tried to solve)
| improve this answer | |
  • Nice edit(s), but your original answer did lead me in the right direction, despite being terse and missing a very key detail - you only said "proxy", not "reverse proxy" (as evident in your 7 edits). This made my journey to the solution longer than needed (thank goodness for this SO post, link, which is the best answer I've ever seen on an online community/forum in 22 years). Don't get me wrong I am grateful for your help, but bad questions isn't the only problem with the Q&A experience – crashintoty Jul 4 '16 at 8:39
1

The best way, i think is nginx and ngx_http_proxy_module. It highly scalable, fast and functional. You can configure encryption with one certificate for all site, it quite transparent. For very simple example add dirrective in nginx srv config:

location /srv1 {
    proxy_pass       http://server1;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;
}
location /srv2 {
    proxy_pass       http://server2;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;
}

Now if you try pass to http://nginx/srv1 you will see response from server1. Also, you can split configuration for two domains, and each must contain one location / with porxy_pass as in the example above.

| improve this answer | |
  • But I'm looking for something like www.bizriteapp.com -> 192.168.1.10 (IIS server), www.fundevapp.com -> 192.168.1.11 (apache server), www.moneymakingdevapp.com -> 192.168.1.11 (apache server), dev1git.fundevapp.com -> 192.168.1.11 (apache server), schooldevapp.com -> 192.168.1.11 (apache server), etc. Is this possible or am I restricted to subdirectories? – crashintoty Jul 2 '16 at 2:17
  • > Also, you can split configuration for two domains, and each must contain one location / with porxy_pass as in the example above. It possible. Just create server nginx config for each domain like this: vpaste.net/NPuDw – KarmicDude Jul 2 '16 at 3:36
1

The technology you are looking for is called a reverse proxy. You can use your existing front end server as a reverse proxy for your backend/dev server, it's really very straightforward. Having your front end terminate the SSL is easy too.

There are lots of Q&A about using apache as a reverse proxy already on SF

| improve this answer | |
0

Yes, the folks are right, reverse proxy is the method I want to use here. I got it to work beautifully by setting up a new virtual machine and installing nginx as the reverse proxy server. The new nginx server now acts as the "front end server" and my Ubuntu(14.04.4)/apache(2.4.7) and Windows/IIS servers (with all my sites) now act as the "back end servers". I simply changed the port forward entry for port 80/http in the router to reflect the new reverse proxy server's IP address and configured my nginx and apache configuration files as below.

My nginx conf file (/etc/nginx/sites-enabled/default):

server {
# catch all for all other domains and sub-domains that are pointing here, but don't have a site hosted here (or that I'm too lazy to track down)
return 404;
}

server {

#
# stupidwindowsserveristillcantgetridof.com - line of business windows server
#

server_name stupidwindowsserveristillcantgetridof.com www.stupidwindowsserveristillcantgetridof.com;

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://10.1.1.10:80;
}

}

server {

#
# dev.domain1.com - web dev app/project #1
#

server_name dev.domain1.com;

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://10.1.1.20:80;
}

}

server {

#
# beta.domain2.com - web dev app/project #2
#

server_name beta.domain2.com;

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://10.1.1.20:80;
}

}

server {

#
# domain3.com - web dev app/project #3
#

server_name domain3.com;

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://10.1.1.20:80;
}

}

A sample of a virtual host corresponding to a web dev project domain name in my apache conf file:

#
# Virtual host for dev.domain1.com - web dev app/project #1
#

<VirtualHost *:80>
ServerAdmin admin@domain1.com
    ServerName dev.domain1.com
#ServerAlias dev.domain1.com
    DocumentRoot /var/www/add_on_domain/dev.domain1.com

    <Directory /var/www/add_on_domain/dev.domain1.com>
            Options -Indexes +FollowSymLinks +MultiViews
            AllowOverride All
    Require all granted 
    </Directory>

ErrorLog ${APACHE_LOG_DIR}/dev.domain1.com-error.log
CustomLog ${APACHE_LOG_DIR}/dev.domain1.com-access.log combined
</VirtualHost>

Hope this helps someone else more efficiently.

P.S. - I plan on adding the SSL/https stuff at a later time

| improve this answer | |
  • Also, I had to update the base url in the config/settings for a number of my custom apps, Wordpress installations and even some .htaccess files to get sites displaying properly again after moving away from custom ports so be aware of that if your url/uri changes. – crashintoty Jul 4 '16 at 9:54

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.