0

How would I set my webservers to work in way described below?

  • Http request: mypublic.com ---> handled normally by nginx as it is set up already (listen 80;)

  • Http request: myprivate.com ---> handled by apache set up to work on 8080 (listen 8080)

I'd like to avoid including ports when typing address in browser, some kind of mockup (proxy?/squid?) at nginx. Both of domains are pointing to my machine and set up by named.

4 Answers 4

2
+50

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:

0
6

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>
4
  • You can do this with nginx too.
    – user9517
    Aug 29, 2012 at 9:03
  • Could you please post a config/reference link how to setup nginx for this purpose? I've also edited the topic and question to be more concrete.
    – Darj
    Sep 23, 2012 at 0:11
  • @AdrianK.: You really shouldn't revise a question like this. What you should do is ask a different question based on the answers to the original.
    – user9517
    Sep 23, 2012 at 20:04
  • ah, ok, sorry, my fault. I will do that next time. I just didn't want to spam with multiple questions.
    – Darj
    Sep 23, 2012 at 20:06
0

You can use apache2 mod_rewrite. You can define the appropriate conditions and rules to the rewrite the requested URL.

1
  • The thing is that I need to set it on nginx as it is my main public domain and :80 webserver.
    – Darj
    Sep 23, 2012 at 0:12
0

For nginx, create a virtual host for myprivate.com and pass it to apache that is configured to listen for myprivate.com on port 8080

server { listen 80; server_name myprivate.com;

# proxy it to Apache listening on 127.0.0.1:8080

location / {
    proxy_pass   http://127.0.0.1:8080;
}

}

That should do.

Then on apache create a virtual host to listen for myprivate.com.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .