0

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.

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/;
    ...
}
| improve this answer | |
  • 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. – lanrat May 21 '17 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. – Lukáš Viktora Sep 17 '19 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.