Tips to optimize LEMP server on CentOS

MooseLucifer

Well-known member
Registered
Joined
May 20, 2016
Messages
149
Points
28
After installation is complete LEMP on CentOS, you will need to make some customizations to ensure that the system works faster, speeding up website. Below are some of their operations done every time you install the server.

1. Enable gzip compression

Open the file to install nginx

Code:
sudo nano /etc/nginx/nginx.conf
Adjust Gzip settings

Code:
...
http {
...

# enable gzip compression
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# end gzip configuration
}
...
Reload nginx

Code:
sudo /etc/init.d/nginx reload
2. Make Browsers Cache Files Static On nginx

Open the default virtual host file or your custom file

Code:
sudo nano /etc/nginx/conf.d/default.conf
Change the settings as shown below.

Code:
[...]
server {
        [...]
        location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$  {
              expires 365d;
        }
        [...]
}
[...]
Reload Nginx

Code:
sudo /etc/init.d/nginx reload
Good luck!
 

VirtuBox

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
Points
83
Good tips !
But you can use more nginx.

allow all statics files to stay in browser cache and use tcp_nodelay to force nginx to send all the files in the same time.

Code:
location ~* \.(?:css|js|txt)$ {
    expires 1y;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay off;
    add_header Cache-Control "public";
}

#Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
    expires 1M;
    access_log off;
    add_header Cache-Control "public";
}


location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
    expires 1M;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay off;
    add_header Cache-Control "public";
}
And to secure your server and protect your visitors always use :
Code:
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
Last step and it's the hardest to do, add a content-security-policy -> http://content-security-policy.com
 
Newer Threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top