Can nginx be used as a reverse proxy for a backend websocket server?

You can’t use nginx for this currently[it’s not true anymore], but I would suggest looking at HAProxy. I have used it for exactly this purpose. The trick is to set long timeouts so that the socket connections are not closed. Something like: timeout client 86400000 # In the frontend timeout server 86400000 # In the … Read more

UnicodeEncodeError: ‘ascii’ codec can’t encode character

For anyone encountering this problem when running Django with Supervisor, the solution is to add e.g. the following to the supervisord section of Supervisor’s configuration: environment=LANG=”en_US.utf8″, LC_ALL=”en_US.UTF-8″, LC_LANG=”en_US.UTF-8″ This solved the problem for me in Supervisor 3.0a8 running on Debian Squeeze. Also make sure Supervisor re-reads the configuration by running: supervisorctl reread supervisorctl restart myservice … Read more

Dynamic proxy_pass to $var with nginx 1.0

I’ve recently stumbled upon this need myself and have found that in order to use variables in a proxy_pass destination you need to set a resolver as your error.log would most probably contain something like no resolver defined to resolve … The solution in my case was to setup the following using a local DNS … Read more

nginx: use environment variables

With NGINX Docker image Apply envsubst on template of the configuration file at container start. envsubst is included in official NGINX docker images. Environment variable is referenced in a form $VARIABLE or ${VARIABLE}. nginx.conf.template: user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { server { listen 80; location … Read more

Nginx location “not equal to” regex

According to nginx documentation there is no syntax for NOT matching a regular expression. Instead, match the target regular expression and assign an empty block, then use location / to match anything else So you could define something like location ~ (dir1|file2\.php) { # empty } location / { rewrite ^/(.*) http://example.com/$1 permanent; }

Assigning vhosts to Docker ports

This answer might be a bit late, but what you need is an automatic reverse proxy. I have used two solutions for that: jwilder/nginx-proxy Traefik With time, my preference is to use Traefik. Mostly because it is well documented and maintained, and comes with more features (load balancing with different strategies and priorities, healthchecks, circuit … Read more

How to add a response header on nginx when using proxy_pass?

add_header works as well with proxy_pass as without. I just today set up a configuration where I’ve used exactly that directive. I have to admit though that I’ve struggled as well setting this up without exactly recalling the reason, though. Right now I have a working configuration and it contains the following (among others): server … Read more