I am making a small TS application but got stuck while setting up reverse proxy. I have been trying to fix this for a few days, here's by current setup: Docker compose:
version: '3.4'
proxy:
image: nginx
build:
dockerfile: ./nginx/Dockerfile
ports:
- "80:80"
restart: always
container_name: nginx
translation_web:
image: httpd
build:
dockerfile: ./translate/Dockerfile
container_name: translation_web
ports:
- "8080:80"
expose:
- "80"
nginx .conf:
server {
listen 80;
server_name localhost;
location /preklad {
proxy_pass http://translation_web:80;
proxy_set_header Host $http_host;
}
}
Here's what I think I am doing: I am forwarding to port 80 (within composer created network) of translation_web HTTPD container.
When I access HTTPD container on port 8080 (port that has been mapped to host machine) through browser, it returns a website (expected behaviour)
When I access HTTPD container on port 80 from nginx container through cURL, HTTPD returns a website (again, expected)
But when I use proxy_pass in nginx container, and go to localhost, I see 404 response from HTTPD (not nginx).
This seems very odd to me because the 404 response from HTTPD indicates that there is a successful forward, however the path to resources somehow changes. Thanks in advance.
I've run into the same issue.
Well, as this serverfault and this reddit post point out... And as always in this kind of situation, we were missing a /
Here is how your nginx.conf should look like :
server {
listen 80;
server_name localhost;
location /preklad {
proxy_pass http://translation_web:80/;
proxy_set_header Host $http_host;
}
}
At least, from the research and experimentation I did, this worked for me, but I'm still no expert on reverse-proxies and particularly Nginx. Still, hope I could help someone with the same issue as ours.