Home Using variables in proxy_pass on nginx
Reply: 0

Using variables in proxy_pass on nginx

user1220
1#
user1220 Published in April 25, 2018, 8:23 am

I try to redirect http://localhost/couch to http://couchdb:5984. CouchDB could run from a Docker Container, a cloud instance or anything else. Thing is it may not run when Nginx is fired up, which is why I want to use variables.

This Nginx conf works:

http {
    server {
        listen 80;
        resolver 127.0.0.1;
        location /couch/ {
            rewrite /couch/(.*) /$1 break;
            proxy_pass http://couchdb:5984;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}

but not this:

http {
    server {
        listen 80;
        resolver 127.0.0.1;
        location /couch/ {
            rewrite /couch/(.*) /$1 break;
            set $target http://couchdb:5984;
            proxy_pass $target;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}

I've read a lot of doc about variables and set and proxy_pass but I can't understand why this "supposed to be" simple conf won't work...

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.328233 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO