Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

up vote 2 down vote accepted
+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:

share|improve this answer

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>
share|improve this answer
    
You can do this with nginx too. –  Iain Aug 29 '12 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. –  Adrian K. Sep 23 '12 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. –  Iain Sep 23 '12 at 20:04
    
ah, ok, sorry, my fault. I will do that next time. I just didn't want to spam with multiple questions. –  Adrian K. Sep 23 '12 at 20:06

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

share|improve this answer
    
The thing is that I need to set it on nginx as it is my main public domain and :80 webserver. –  Adrian K. Sep 23 '12 at 0:12

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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