NGINX + uWSGI Connection Reset by Peer

make sure to consume your post data in your application for example if you have a Django/python application def my_view(request): # ensure to read the post data, even if you don’t need it # without this you get a: failed (104: Connection reset by peer) data = request.DATA return HttpResponse(“Hello World”) Some details: https://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html

SSL Pass-Through in Nginx Reverse proxy?

Not sure how much it can work in your situation, but newer (1.9.3+) versions of Nginx can pass (encrypted) TLS packets directly to an upstream server, using the stream block : stream { server { listen 443; proxy_pass backend.example.com:443; } } If you want to target multiple upstream servers, distinguished by their hostnames, this is … Read more

Substitute environment variables in NGINX config from docker-compose

Since nginx 1.19 you can now use environment variables in your configuration with docker-compose. I used the following setup: # file: docker/nginx/templates/default.conf.conf upstream api-upstream { server ${API_HOST}; } # file: docker-compose.yml services: nginx: image: nginx:1.19-alpine volumes: – “./docker/nginx/templates:/etc/nginx/templates/” environment: NGINX_ENVSUBST_TEMPLATE_SUFFIX: “.conf” API_HOST: api.example.com I’m going off script a little from the example in the documentation. … Read more

Intercepting backend 301/302 redirects (proxy_pass) and rewriting to another location block possible?

You could use proxy_redirect directive: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect Nginx will still return 301/302 to the client but proxy_redirect will modify Location header and the client should make a new request to the URL given in the Location header. Something like this should make the subsequent request back to nginx: proxy_redirect http://upstream:port/ http://$http_host/;

Meteor WebSocket handshake error 400 with nginx

WebSockets are fast and you don’t have to (and shouldn’t) disable them. The real cause of this error is that Webfactions uses nginx, and nginx was improperly configured. Here’s how to correctly configure nginx to proxy WebSocket requests, by setting proxy_set_header Upgrade $http_upgrade; and proxy_set_header Connection $connection_upgrade;: # we’re in the http context here map … Read more

nginx redirect HTTPS to HTTP

The answer above will work, you need to generate a self signed cert (or have a real one) and configure nginx as such: server { listen *:443; ssl on; server_name domain.com; rewrite ^(.*) http://domain.com$1 permanent; ssl_certificate /data/certs/domain.crt; ssl_certificate_key /data/certs/domain.key; } Keep in mind, if it is a self signed cert the browser will give you … Read more

NGINX try_files + alias directives

We could not get it to work by specifying root within the location block. The solution for us was to use alias instead. Note that it is necessary repeat the location’s path twice in the try_files directive, and then also in the .php configuration block: server { server_name localhost; root /app/frontend/www; location /backend/ { alias … Read more