502 Bad Gateway

This error means that NGINX cannot get a response from one of the services on the server. Quite often this error occurs when NGINX works in conjunction with Apache, Memcached and also handles PHP-FPM requests.
This problem is usually caused by a disabled service (in this case you should check the status of your partner and, if necessary, restart it).

Also, for PHP-FPM, it's necessary to check the permissions of the socket.
Make sure you have the correct permissions in /etc/php-fpm.d/www.conf

listen = /tmp/php5-fpm.sock  
listen.group = www-data  
listen.owner = www-data  

504 Gateway Time-out

This error means that nginx is taking a long time to get a response from some service. This happens if the service nginx is working with is too slow.
The problem can be solved by increasing the timeout time.

If you are using NGINX+Apache, you can change the configuration file

server {  
.. 
   send_timeout 800;
   proxy_send_timeout 800;
   proxy_connect_timeout 800  
   proxy_read_timeout 800  
.. 
}

Also, the reason could be complex and therefore long php processing in PHP-FPM.

Here, too, you can increase the timeout time

location ~ \.php$ {  
   include fastcgi_params;
   { fastcgi_index index.php 
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name 
   fastcgi_pass unix:/tmp/php5-fpm.sock  
   fastcgi_read_timeout 800;
}

413 Request Entity Too Large

Error means you've tried to upload too big file. The nginx default setting is 1Mb.
To fix this error you need to find the following line in nginx.conf

client_max_body_size 1m;  

and replace the value with the desired one. For example, we will increase the size of the downloaded files to 30Mb

client_max_body_size 30m;  

Also, you can disable the response body check completely with a value of zero:

client_max_body_size 0;  

After each change you make to the configuration file, you must reboot nginx

How to reboot nginx

Use restart or reload to reboot NGINX.

Command in the console:

service nginx reload  

Or

/etc/init.d/nginx reload

Or

nginx -s reload  

These commands will stop and restart the NGINX server.

You can restart the configuration file without restarting NGINX like this

nginx -s reload  

You can check if the configuration is correct with the command

nginx -t  

What is the difference between reload and restart*

How to restart in NGINX:

  • The command is sent to the server

  • Server parses the configuration file

  • If the configuration contains no errors, new processes open with the new server configuration and the old ones stop working smoothly

  • If the configuration contains errors, the

  • restart the process of server restart is interrupted, the server does not start

  • reload server rolls back to the old configuration, operation continues

restart terminates abruptly, reload does it smoothly.

Updated Feb. 25, 2019