Post Archive
Nginx May Cut You Off Early
How the default configuration bit me.
I very recently launched shadowsinthegrass.com, a crowd-funding website for a short film I am working on. As a donator, you are able to upload an avatar to be presented with your credit. I had limited the file size to 2MB... or so I had thought.
Underneath, the site is built with Flask, served with Gunicorn, and behind an Nginx reverse proxy.
Unfortunately, I received reports that some uploads were failing and reported as "Error: undefined" to the user. Strangely, it didn't seem to be an error in the Python app, as I was not receiving any tracebacks when this error occurred.
It turns out that Nginx has some default configuration that I wasn't expecting.
Pseudo suExec with PHP Behind Nginx
For those who don't want to run more than one php-cgi... for some reason.
I recently started transitioning all of the websites under my management from Apache to nginx (mainly to ease running my Python webapps via gunicorn, but that is another story).
Since nginx will not directly execute PHP (via either CGI or nginx-managed FastCGI), the first step was to get PHP running at all. I opted to run php-cgi
via daemontools; my initial run
script was fairly straight forward:
1 2 | #!/usr/bin/env bash exec php-cgi -b 127.0.0.1:9000 |
Couple this with a (relatively) straight forward nginx configuration and the sites will already start responding:
server { listen 80; server_name example.com root /var/www/example.com/httpdocs; index index.php index.html; fastcgi_index index.php; location ~ \.php { keepalive_timeout 0; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$uri; fastcgi_pass 127.0.0.1:9000; } }
The tricky part came when I wanted to run PHP under the user who owned the various sites. I could have (and perhaps should have) opted to spin up a copy of php-cgi
for each user, but I decided to try something a little sneakier; PHP will set its own UID on each request.
There are no more posts tagged "Nginx".