nginx: learnings from a noob
At the university, we run a server that also hosts ShinyProxy for our apps. In front of ShinyProxy, we place an nginx reverse proxy. It took me a while to understand nginx’s configuration settings. Today, I want to share some insights that may be helpful for beginners. And, of course, for my future self—since I don’t configure nginx very often, I tend to make the same mistakes again after a few months.
Reload Instead of Restart
You can reload the nginx service using systemctl nginx reload
, which avoids downtime. If you use restart instead, your server will be unavailable for a few seconds.
nginx -t
With nginx -t
, you can check all your configurations for syntax errors. Always do this before reloading! However, this doesn’t mean there won’t be any errors—only that the most severe ones are eliminated.
Error Log
If nginx fails with an error message, check the error log, usually located at:
/var/log/nginx/error.log
Check If Newly Configured Ports Are Open
A common mistake is configuring ports that are already in use. If that happens, nginx will refuse to start, and all your sites will be down. Therefore, always check in advance whether the ports are free. The easiest way is to use net-tools (install it first if necessary):
sudo netstat -tulpn
For example, Apache might be running by default and blocking port 80. In that case, simply stop and disable the Apache service.
Rewrites with () and $1
rewrite ^/directory/(.*)$ /$1 break;
proxy_pass ...;
This simply means that the part after directory
is passed on to the proxy.
Certificates
SSL ports won’t work without certificates—nginx will not start!
Certificates must match the server_name
exactly unless they are wildcard certificates.
client_max_body_size
This is crucial for Shiny, as it determines the maximum upload file size, independent of Shiny’s own settings. The problem is that if you don’t know this setting, the error message won’t make much sense.
I use 5MB:
client_max_body_size 5m;