I have two services running in my docker, /app1
on 8080 and /app2
on 3000. I setup my nginx reverse proxy for the services on port 80.
In port 3000 (main server),
If I request http://localhost:3000/, I get my index.html
with files. If I request http://localhost:3000/files, I get my files as a json which is perfect.
But in port 80 (nginx port),
When I inspect the page, I see these two names in network tab:
files
with request URL as http://localhost/app2/files and response of this says
“failed to load response data: no content available because this request was redirected”
files/
with request URL as http://localhost/files. the above request was redirected to this request, which is not to be done.
Please find my config below and suggest me how to fix it 🙂
PS: The server works perfectly when I run it on main port (not the nginx proxy).
My nginx.conf:
server {
listen 80;
server_name localhost;
rewrite ^([^.]*[^/])$ $1/ permanent;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ =404;
}
location /app1/ {
proxy_pass http://app1:8080/;
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-Forwarded-Proto $scheme;
}
location /app2/ {
proxy_pass http://app2:3000/;
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-Forwarded-Proto $scheme;
}
location /app2/files/ {
proxy_pass http://app2:3000/files/;
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-Forwarded-Proto $scheme;
}
}
Shashank Bhake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.