设置nginx优化隐藏版本号,修改用户和组,网页缓存时间,更改进程数,以及防盗链的代码内容
======================== Hide version numbers, modify users and groups
Method One:
Cd/opt/nginx-1.12.0/src/core
Vim Nginx.h
#define Nginx_version "1.12.0"//tamper with the version number before compiling the installation to achieve hidden effect
Method Two:
Vim/usr/local/nginx/conf/nginx.conf
Server_tokens off; Add or modify
Vim/usr/local/nginx/conf/nginx.conf
User Nginx Nginx; Add directly
Add users and groups directly when compiling the installation
PS aux | grep nginx
The main process is created by the root account, and the child process is created by Nginx
=====================网页缓存时间,等待超时,更改进程数
Vim/usr/local/nginx/conf/nginx.conf
Location ~. (Gif|jepg|png|bmp|ico) $ {
root/var/www/benet.com;
Expires 1d; Cache a Day
}
Add a wait timeout in parentheses in the HTTP protocol
Keepalive_timeout 65 180; Whichever is the following number
Client_header_timeout 80;
Client_body_timeout 80;
Modify or add the number of processes directly at the beginning of the file
Worker_processes 2;
Events {
Worker_connections 4096;
}
Worker_processes 2; 2 sub-processes per CPU
Worker_connections 4096; Each subprocess processes 4,096 requests
==========================压缩设置
Vim/usr/local/nginx/conf/nginx.conf
gzip on;
Gzip_buffers 4 64k;
Gzip_http_version 1.1;
Gzip_comp_level 2;
Gzip_min_length 1k;
Gzip_vary on;
Gzip_types text/plain text/javascript application/x-javascript text/css text/xml
Application/xml Applicatin/xml+rss;
Turn on gzip compression
Compress 4 packets per package 64k
Identify the HTTP protocol version, which defaults to 1.1
The compression level of gzip is 2
Compress up to 1KB
Let the front-end cache server cache gzip-compressed pages
adding compression function parameters
=================================== Anti-theft chain
If an anti-theft chain is required in the set of virtual host servers, add the content to the appropriate virtual host settings in parentheses
Vim/usr/local/nginx/conf/nginx.conf
location ~* \.(gzip|gif|swf)$ { valid_referers none blocked *.benet.com benet.com; if ( $invalid_referer ) { rewrite ^/ http://www.benet.com/error.png; } }重新添加防盗链规则
Some configuration contents of the main configuration file in Nginx
Nginx Optimizer, hide version number, modify user and Group, page cache time, change process number, and anti-theft chain