Nginx configuration file nginx.conf specific explanation

Source: Internet
Author: User

#定义Nginx执行的用户和用户组
User www www;

#nginx进程数. The recommended setting is equal to the total CPU core number.


Worker_processes 8;

#全局错误日志定义类型, [Debug | info | notice | warn | error | crit]
Error_log Ar/loginx/error.log Info;

#进程文件
PID Ar/runinx.pid;

#一个nginx进程打开的最多文件描写叙述符数目, the theoretical value should be the number of open files (System value ulimit-n) and the number of nginx processes. However, the Nginx allocation request is not uniform, so the recommendation is consistent with the Ulimit-n value.


Worker_rlimit_nofile 65535;

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

#设定httpserver
http
{
Include Mime.types; #文件扩展名与文件类型映射表
Default_type Application/octet-stream; #默认文件类型
#charset Utf-8; #默认编码
Server_names_hash_bucket_size 128; #server名字的hash表大小
Client_header_buffer_size 32k; #上传文件限制大小
Large_client_header_buffers 4 64k; #设定请求缓
Client_max_body_size 8m; #设定请求缓
Sendfile on; #开启高效文件传输模式, the sendfile directive specifies whether Nginx calls the Sendfile function to output the file, and for normal applications set to ON, suppose to download applications such as disk IO heavy load applications. Can be set to off. To balance disk and network I/O processing speed and reduce the load on the system. Note: If the picture is not normal, change this to off.


AutoIndex on; #开启文件夹列表訪问, the appropriate download server, the default shutdown.
Tcp_nopush on; #防止网络堵塞
Tcp_nodelay on; #防止网络堵塞
Keepalive_timeout 120; #长连接超时时间. Unit is seconds

#FastCGI相关參数是为了改善站点的性能: Reduce resource usage and increase access speed.

The following numbers can be understood by literal means.
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 assumption is squid2.5 please use 1.0)
Gzip_comp_level 2; #压缩等级
Gzip_types text/plain application/x-javascript text/css application/xml;
#压缩类型. The default is already included textml, the lower face will not have to write, write up also no problem. But there will be a warn.
Gzip_vary on;
#limit_zone crawler $binary _remote_addr 10m; #开启限制IP连接数的时候须要使用

Upstream blog.ha97.com {
#upstream的负载均衡. Weight is a weight. Ability to define weights based on machine configuration. Weigth The weighted value, the higher the weight, the greater the probability of being allocated.


Server 192.168.80.121:80 weight=3;
Server 192.168.80.122:80 weight=2;
Server 192.168.80.123:80 weight=3;
}

#虚拟主机的配置
Server
{
#监听port
Listen 80;
#域名能够有多个, separated by a space
server_name www.ha97.com ha97.com;
Index index.html index.htm index.php;
root/data/www/ha97;
Location ~. *. (PHP|PHP5)? $
{
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include fastcgi.conf;
}
#图片缓存时间设置
Location ~. *. (gif|jpg|jpeg|png|bmp|swf) $
{
Expires 10d;
}
#JS和CSS缓存时间设置
Location ~. *. (JS|CSS)? $
{
Expires 1h;
}
#日志格式设定
Log_format access ' $remote _addr-$remote _user [$time _local] "$request"
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" $http _x_forwarded_for ';
#定义本虚拟主机的訪问日志
Access_log Ar/loginx/ha97access.log access;

#对 "/" Enable reverse Proxy
Location/{
Proxy_pass http://127.0.0.1:88;
Proxy_redirect off;
Proxy_set_header X-real-ip $remote _addr;
#后端的Webserver能够通过X-forwarded-for Get the user real IP
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
#下面是一些反向代理的配置, optional.
Proxy_set_header Host $host;
Client_max_body_size 10m; #同意客户端请求的最大单文件字节数
Client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,
Proxy_connect_timeout 90; #nginx跟后端server连接超时时间 (proxy connection timed out)
Proxy_send_timeout 90; #后端server数据回传时间 (proxy send timeout)
Proxy_read_timeout 90; #连接成功后, Backend server response time (proxy receive timeout)
Proxy_buffer_size 4k; #设置代理server (nginx) buffer size for saving user header information
Proxy_buffers 4 32k; #proxy_buffers缓冲区, the average page setting below 32k
Proxy_busy_buffers_size 64k; #高负荷下缓冲大小 (proxy_buffers*2)
Proxy_temp_file_write_size 64k;
#设定缓存文件夹大小, greater than this value, will be passed from Upstreamserver
}

#设定查看Nginx状态的地址
Location/nginxstatus {
Stub_status on;
Access_log on;
Auth_basic "Nginxstatus";
Auth_basic_user_file confpasswd;
#htpasswd文件的内容能够用apache提供的htpasswd工具来产生.
}

#本地动静分离反向代理配置
#全部jsp的页面均交由tomcat或resin处理
Location ~. (JSP|JSPX|DO)? $ {
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_pass http://127.0.0.1:8080;
}
#全部静态文件由nginx直接读取不经过tomcat或resin
Location ~. *. (HTM|HTML|GIF|JPG|JPEG|PNG|BMP|SWF|IOC|RAR|ZIP|TXT|FLV|MID|DOC|PPT|PDF|XLS|MP3|WMA) $
{Expires 15d;}
Location ~. *. (JS|CSS)? $
{Expires 1h;}
}
}

For more specific module references, please refer to: Http://wiki.nginx.org/Main

Nginx configuration file nginx.conf specific explanation

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.