Nginx proxy pass configuration docker Nginx proxy pass configuration docker docker docker

Nginx proxy pass configuration docker


Inside your server {} block you want:

location /app1 {    rewrite ^/app1(.*) /$1 break;    proxy_pass http://hostname:3001/;    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;}location /app2 {    rewrite ^/app2(.*) /$1 break;    proxy_pass http://hostname:3002/;    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;}

The rewrite rule here will pass the correct uris to the ports


You can make every app listens on a separate port (e.g. 3000 and 3001) then configure your nginx as follows (include it inside the server {} definition block):

 location /app1 {  proxy_pass        http://localhost:3000;  proxy_set_header  X-Real-IP  $remote_addr; } location /app2 {  proxy_pass        http://localhost:3001;  proxy_set_header  X-Real-IP  $remote_addr; }