How to make proxy on nginx?

Solution 1:

With nginx, you could do this by configuring two virtual servers and proxy_pass'ing one of them to Apache running on port 8080:

server {
    listen 80;
    server_name mypublic.com;
    ...
}

server {
    listen 80;
    server_name myprivate.com;

    location / {
        proxy_pass http://myprivate.com:8080;
    }
}

See here for docs:

  • http://nginx.org/r/server_name
  • http://nginx.org/r/proxy_pass

Solution 2:

You can't do this directly with DNS as DNS doesn't deal with ports.

You can use some form of proxying on port 80 to pass requests to port 8080. An example with apache might be

<VirtualHost *:80>
    Servername contoso.com
    .
    .
    .
</VirtualHost>

<VirtualHost *:80>
    Servername apache.contoso.com
    ProxyRequests Off
    <Proxy *>
            Order deny,allow
            allow from all
    </Proxy>         
    ProxyPreserveHost On
    ProxyPass / http://contoso.com:8080/
    ProxyPassReverse / http://contoso.com:8080/     

</VirtualHost>