1

I'm trying to run lets-chat inside docker behind nginx acting as a reverse proxy so that lets-chat will be accessible on /chat over HTTP.

In the past when using nginx as a reverse proxy inside of docker for another docker container I set resolver 127.0.0.11 valid=300s; so that nginx uses the docker DNS server and set proxy_pass as a variable so that the nginx container can start without needing the upstream web service to be ready. Example.

However, lets-chat seems to need proxy_redirect default; which the nginx configuration does not allow combined with a variable proxy_pass.

Does anyone know a way around this to get the desired effect? I've tried a few manual redirects with no luck. My relevant nginx config is below.

# use docker's nameserver for changing container IPs resolver 127.0.0.11 valid=300s; resolver_timeout 5s; server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } location /chat/ { # I would like this part to work #set $chat_backend http://chat_server:8080/; #proxy_pass $chat_backend; # But I can only get it to work like this proxy_pass http://chat_server:8080/; proxy_redirect / /chat/; proxy_redirect default; # this line errors when setting a variable to proxy_pass proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; } } 

Thanks.

2 Answers 2

0

From the manual, the following statements are equivalent:

location /chat/ { proxy_pass http://chat_server:8080/; proxy_redirect default; } location /chat/ { proxy_pass http://chat_server:8080/; proxy_redirect http://chat_server:8080/ /chat/; } 

proxy_redirect default does not work if the value of proxy_pass is not a literal string, however, proxy_redirect itself can also be constructed from variables.

So this solution may work for you:

location /chat/ { set $chat_backend http://chat_server:8080/; proxy_pass $chat_backend; proxy_redirect / /chat/; proxy_redirect $chat_backend /chat/; ... } 
2
  • Thanks for the response, that was one one of the things I tried, but unfortunately when I use that and visit /chat/ I get stuck in a redirect loop to /chat/login. Commented May 21, 2017 at 16:58
  • Some web apps have a problem with redirection. For that cases there are quite frequently option under app as behind proxy. Did you tried to go to the service directly without proxy? Maybe that helps you because under browser you will see all redirects. This helped me in a case of transmission app because there was another URL for fastcgi. Commented Sep 17, 2019 at 21:20
0

I set resolver 127.0.0.11 valid=300s;

Go and read the link you provided - you set this in the wrong place.

server_name localhost;

I am struggling to imagine how this makes ANY sense. the chat service will only be accessible from the host where nginx is running. And if you are using docker in a sensible way that is a docker instance and NOT where our browser is running.

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.