1

I have an nginx container with -p 8080:80. I am trying arrange my proxy_pass so that my browser client can go to <ip of container server>:8080/app and it will be redirected to another container listening with -p 8000:8000 as <ip>:8000 (no /app). I have some pretty simple config files:

default.conf:

server { listen 80; listen [::]:80; server_name localhost; error_log stderr debug; access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } 

app.conf:

server { listen 80; server_name mydomain.com; error_log stderr debug; location /app { proxy_pass http://<ip of server running containers>:8000/; } } 

I have played around with different combinations of trailing slashes on location and proxy_pass. The config files as shown above give me a 301 error if I type <ip>:8080/app into the browser and gives me the starting page of the app if I use <ip>:8080/app/ (trailing slash), but then other requests from the app get 404. If I make the location /app/, the app tries to start but then says "Please enable java script". The container app works if I go directly to it (<ip>:8000). I believe that nginx is somehow appending /app or /app/ to the proxy url and this messing up the app when it tries to GET resources, but I can't seem to find a way to go to the proxy url as is in the proxy_pass. I was going to look into using rewrite but thought I'd post this first in the hope that someone will know how to write the config files that will work.

2
  • Generally, what you're trying to achieve cannot be done using only nginx; it requires proper support from the backend application. I tried to give an in-depth explanation of why that is the case in the first part of this StackOverflow answer. While some workarounds are possible in most (not all) cases, they are still just workarounds and tend to be more or less hacky or unreliable. Some of those workarounds are referenced in the comment under the aforementioned answer. Commented Jul 30 at 1:57
  • thanks for the answer. was hoping i could make it work, but at least now i can stop beating my head on the wall Commented Jul 30 at 23:15

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.