Change Host header in nginx reverse proxy

You cannot use proxy_pass in if block, so I suggest to do something like this before setting proxy header: set $my_host $http_host; if ($http_host = “beta.example.com”) { set $my_host “www.example.com”; } And now you can just use proxy_pass and proxy_set_header without if block: location / { proxy_pass http://rubyapp.com; proxy_set_header Host $my_host; }

What does the Resolver param in nginx do?

The nginx resolver directive is required because the system resolver blocks. Nginx is a multiplexing server (many connections in one OS process), so each call of system resolver will stop processing all connections till the resolver answer is received. That’s why Nginx implemented its own internal non-blocking resolver. If your config file has static DNS … Read more

Nginx location directive doesn’t seem to be working. Am I missing something?

The problem here is that only the “best” location directive gets taken, in this order: location = <path> (longest match wins) location ^~ <path> (longest match wins) location ~ <path> (first defined match wins) location <path> (longest match wins) Using this ruleset, your /phpmyadmin location directive is beaten out by the regular expression “.php$” location … Read more

Nginx reverse proxy multiple backends

You can match the different URLs with server {} blocks, then inside each server block, you’d have the reverse proxy settings. Below, an illustration; server { server_name client.example.com; # app1 reverse proxy follow proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://x.x.x.100:80; } server { server_name client2.example.com; # app2 reverse proxy settings follow … Read more