All settings and commands followed by a server with Centos, but configuring servers to other systems is not much different.
Setting data compression by Nginx.
Open the configuration file Nginx, located at /etc/nginx/nginx.conf
And in section http {...}, which is in the beginning of the file add what is not there from the example below:
gzip on; gzip_static on; gzip_comp_level 5; gzip_min_length 1024; gzip_proxied any; gzip_types text/plain application/xml application/x-javascript text/javascript text/css text/json;
Configuring caching static files in the browser cache user by Nginx.
In the same file /etc/nginx/nginx.conf down below, find the right design for the site server and appends it:
location ~* ^.+.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|js)$ { root /var/www/user/data/www/site.ru; expires 7d;
where expires 7d — is the number of days as the cache static files should be stored on the user's computer. If you do not make changes to css, js, files of your site and do not change the picture, it makes sense to increase this parameter up to several months or even up to a year.
For illustrative purposes, the site server section of the server that was installed Nginx standard tools panel ISPmanager:
server { server_name site.ru www.site.ru; listen 111.121.152.21; disable_symlinks if_not_owner from=$root_path; set $root_path /var/www/user/data/www/site.ru; location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ { root $root_path; access_log /var/www/nginx-logs/user isp; access_log /var/www/httpd-logs/site.ru.access.log ; error_page 404 = @fallback; }
And now we add here expires 7d , now it looks like this:
server { server_name site.ru www.site.ru; listen 111.121.152.21; disable_symlinks if_not_owner from=$root_path; set $root_path /var/www/user/data/www/site.ru; location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ { root $root_path; expires 7d; access_log /var/www/nginx-logs/user isp; access_log /var/www/httpd-logs/site.ru.access.log ; error_page 404 = @fallback; }
Restart Nginx command:
service nginx restart
Go to their website and enjoy, it has now become a loaded several times faster. And the weight of pages fell from a few megabytes to a few dozen kilobytes!
This article will be useful for owners of virtual and dedicated servers as virtual hosting users do not have access to edit the configuration of Nginx. However, customers virtual hosting , proposed by our organization can always contact our support and our system administrators will make necessary settings for your site.