A
A
account-42017-03-13 16:14:59
Nginx
account-4, 2017-03-13 16:14:59

How to run 2 applications on the same port for nginx?

I raise several sites on one machine. Found config with nginx setup:

server {

listen 80 default;
server_name site1.ru;

location ~* \.(jpg|jpeg|gif|png|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|xml|docx|xlsx)$ {
root /var/www/site1.ru;
index index.html index.php;
access_log off;
expires 30d;
error_page 404 = @fallback;
proxy_cache_valid 404 1m;
}

location ~ /\.ht {
deny all;
}

location / {

proxy_pass http://127.0.0.1:8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $remote_addr;
proxy_set_header Host $host;
proxy_connect_timeout 60;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_redirect off;
proxy_set_header Connection close;
proxy_pass_header Content-Type;
proxy_pass_header Content-Disposition;
proxy_pass_header Content-Length;
}

location @fallback {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $remote_addr;
proxy_set_header Host $host;
}
}

server {

listen 80 default;
server_name site2.ru;

location ~* \.(jpg|jpeg|gif|png|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|xml|docx|xlsx)$ {
root /var/www/site2.ru;
index index.html index.php;
access_log off;
expires 30d;
error_page 404 = @fallback;
proxy_cache_valid 404 1m;
}

location ~ /\.ht {
deny all;
}

location / {

proxy_pass http://127.0.0.1:8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $remote_addr;
proxy_set_header Host $host;
proxy_connect_timeout 60;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_redirect off;
proxy_set_header Connection close;
proxy_pass_header Content-Type;
proxy_pass_header Content-Disposition;
proxy_pass_header Content-Length;
}

location @fallback {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $remote_addr;
proxy_set_header Host $host;
}
}


And frankly, I'm puzzled.

1. How did the author of this config manage to run 2 applications at the same time on 127.0.0.1:8080? Is this correct or is it a typo?

2. How is it done in general correctly? Here I have 2 projects on the node. Should I run them locally on different ports? For example, one at 3000, the second at 3001. After all, when I run it simultaneously on one port, the second application does not start, knocking out an error that the port is busy. How did this pretzel manage to run such a config?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question