I have nginx setup as the defacto port 80. I want to setup django+mod_wsgi on Apache2. I'm worried if I leave Apache2 as 80 it will cause a conflict.

Is it better to avoid the headache and change Apache to a different port?

server {
    listen 80;
    server_name work.domain.org;

    access_log /www/work.domain.org/log/access.log;
    error_log /www/work.domain.org/log/error.log;

    location / {
        proxy_redirect off;

        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header        X-Magic-Header "secret";
        client_max_body_size       10m;

3 Answers 3


In general you want the reverse proxy to listen on the port clients will be connecting to. So in this case you want nginx to be on port 80. The Apache port really doesn't mater, it could be port 80 as long as the port is not no use on the same server with the same IP.

So if your reverse proxy machine doesn't run Apache as well, they both could have been 80. You could also have a secondary IP on the host and have Apache bind to that IP/Port pair and have both nginx and Apache listen on port 80 on the same machine (just different IPs).

For example (nc listens on a specified IP and port):

#Add Secondary IP:
$ sudo ifconfig eth0:1 netmask
# Listen on primary IP:
$ nc -l -p 20200 -s
#Listen on Secondary IP in another Terminal
$ nc -l -p 20200 -s
Show in Yet another Terminal
$ sudo netstat -tapnl | grep 20200 
tcp        0      0*               LISTEN      440/nc          
tcp        0      0*               LISTEN      428/nc 

Think I kind of answered my own question in that:

Starting web server: apache2(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address
no listening sockets available, shutting down
Unable to open logs
invoke-rc.d: initscript apache2, action "start" failed.
Press return to continue.

Can't bind to the same port, therefore I have to choose another. I could've sworn though someone had mentioned set both to port 80, guess I misread.


You can bind them to both the same port, but on different interfaces. For example, you can bind your front-end to your external IP on port 80 and bind the back-end to your localhost on port 80.

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.