Nginx Technology (2) Nginx configuration detailed

Source: Internet
Author: User
Tags epoll sendfile

Configuration of Nginx

1, start Nginx

[Root@centos6 nginx-1.2.9]#/usr/sbin/nginx-c/etc/nginx/nginx.conf   boot nginx
[ROOT@CENTOS6 nginx-1.2.9]# PS- Ef|grep nginx   View process
root   5479   1 0 04:15?    00:00:00 nginx:master process/usr/sbin/nginx-c/etc/nginx/nginx.conf
nginx 5480   0 5479?    00:00:00 nginx:worker process  
root   5534 2377 0 04:22 pts/1  00:00:00 grep nginx
[ROOT@CENTOS6 nginx-1.2.9]# netstat-tulnp|grep nginx     view Nginx listening port
tcp    0   0 0.0.0.0:80         0.0.0.0:*          LISTEN   5479/nginx.conf

2, Stop Nginx

Calmly stop nginx
[ROOT@CENTOS6 ~]# kill-quit $ (cat/var/run/nginx/nginx.pid)
fast Stop nginx
[ROOT@CENTOS6 ~]# Kill-term $ (cat/var/run/nginx/nginx.pid)
 forces all nginx to be stopped
[root@centos6 ~]# kill-9 Nginx

3, restart Nginx

[ROOT@CENTOS6 ~]# Kill-hup $ (cat/var/run/nginx/nginx.pid)
 detects the correctness of Nginx's configuration file
[ROOT@CENTOS6, ~]#/usr/sbin/ Nginx-t-c/etc/nginx/nginx.conf
nginx:the configuration file/etc/nginx/nginx.conf syntax is OK
Nginx:configu Ration file/etc/nginx/nginx.conf test is successful

Configuration of 4,nginx

[Root@centos6 rc0.d]# vim/usr/local/nginx/conf/nginx.conf

(1) Global mode

#启动进程数, usually set to and the number of CPUs equal to
worker_processes 1;
#全局错误日志定义类型, [Debug | info | notice | warn | error | crit]
error_log  logs/error.log info;
#进程文件
pid logs/nginx.pid;
worker_rlimit_nofile65535;
This instruction is when a nginx process opens the maximum number of file descriptors, the theoretical value should be the maximum number of open Text
(ulimit-n) and the number of nginx process, but the Nginx allocation request is not so uniform, so it is best to be consistent with the value of ulimit-n.
now in the linux2.6 kernel open the number of files opened for 65535,worker_rlimit_nofile should be filled in 65535.

(2) Working mode

#工作模式与连接数上限
Events
{
#参考事件模型, use [kqueue | rtsig | epoll |/dev/poll | poll];
The Epoll model is a high-performance network I/O model in the Linux 2.6 version kernel, and if run on FreeBSD, use the Kqueue model. Use
epoll;
#单个进程最大连接数 (maximum number of connections = number of connections * processes)
worker_connections 65535
}

The maximum number of connections to a process is limited by the maximum number of open files on the system, after operating system command Ulimit-n 65535

Worker_connections will not take effect.

(3) Set HTTP server

Include Mime.types; #文件扩展名与文件类型映射表 Default_type Application/octet-stream; #默认文件类型 #charset Utf-8; #默认编码 server_names_hash_bucket_size 128; #服务器名字的hash表大小 Client_header_buffer_size 32k; #上传文件大小限制 large_client_header_buffers 4 64k; #设定请求缓 client_max_body_size 8m; #设定请求缓 sendfile on; #开启高效文件传输模式, the sendfile instruction specifies whether Nginx invokes the Sendfile function to output the file, set to on for the normal application, and, if used for downloading applications disk IO Heavy load application, to balance disk and network I/O processing speed, Reduce the load on the system.
Note: If the picture appears to be abnormal, change this to off. AutoIndex on;
#开启目录列表访问, the appropriate download server, the default shutdown. Tcp_nopush on; #防止网络阻塞 Tcp_nodelay on; #防止网络阻塞 Keepalive_timeout 120; #长连接超时时间, the unit is seconds #FastCGI相关参数是为了改善网站的性能: Reduce resource consumption, improve access speed.
The following parameters can be understood by literal meaning.
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 64k;
Fastcgi_buffers 4 64k;
Fastcgi_busy_buffers_size 128k;
Fastcgi_temp_file_write_size 128k; #gzip模块设置 gzip on; #开启gzip压缩输出 Gzip_min_length 1k; #最小压缩文件大小 gzip_buffers 4 16k; #压缩缓冲区 Gzip_http_version 1.0; #压缩版本 (default 1.1, front End If it is squid2.5 please use 1.0) Gzip_comp_level 2; #压缩等级 gzip_types Text/plain APPLICATION/X-JAVASCRipt Text/css Application/xml;
#压缩类型, the default already contains textml, so there is no need to write, write up also will not have a problem, but there will be a warn.
Gzip_vary on; #limit_zone crawler $binary _remote_addr 10m; #开启限制IP连接数的时候需要使
Set the maximum number of bytes client_max_body_size 20m to allow the client to request the largest single file
   ;
Sets the size of the header buffer for the client's request header. For most requests, the size of 1kb is enough. If you customize the message header or have a larger cookie, you can increase the size of the
    client_header_buffer_size 32k;
Used to specify the maximum number and size of headers cached in a client request, meaning 4 is the number, 32k is the size 
 large_client_header_buffers 4 32k;
Sets the read timeout for the client request header to   return to 408 client_header_timeout when it exceeds this time
    ;
Sets the client request body read timeout time  over this time will return 408
    client_body_timeout;
Specifies the timeout time to respond to the client. This time is limited to two connection activities between the time, if more than this time, the client does not have any activity, Nginx will close the connection
    send_timeout  10;

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/web/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.