Improve how Nginx Handles WordPress

This is still a work in progress, but adding the following lines to your nginx.conf file should improve the way that WordPress functions on your Nginx server.

Add these lines to your http block:

client_max_body_size 512M;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains" always;

Add these lines to each server block that is running WordPress. This should give your site an A+ mark for security on SSLLabs.com. Be sure to replace [X.X.X.X] and [mydomain] with your own info:

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    listen [X.X.X.X]:443 default_server ssl http2;
    ssl_certificate /home/[mydomain]/ssl.combined;
    ssl_certificate_key /home/[mydomain]/ssl.key;
    ssl_protocols TLSv1.2;
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;

I don’t think this has to do with running Nginx, but if you are getting a json parse error when you update a page and you are using the Gutenberg WordPress editor, try installing the Classic WordPress editor and see if that works better. The Gutenberg editor seems to still have some bugs.

Also, if you are getting a lot of white screens while in wp-admin, you probably need to increase your memory limit. Just add the following line to your wp-config file right above where it says ‘Thats all, stop editing!’, but make sure that the amount is not more than what is specified in your php.ini file:

define( 'WP_MEMORY_LIMIT', '128M' );

References

https://www.digitalocean.com/community/tutorials/how-to-optimize-nginx-configuration

https://www.scalescale.com/tips/nginx/502-bad-gateway-error-using-nginx