Nginx配置文件nginx.conf中文详解
2017-03-09 14:31
591 查看
查了下网络资料,对Nginx配置文件nginx.conf的理解整理如下:
view
source
?
view
source
?
001 | #定义Nginx运行的用户和用户组 |
002 | user www www; |
003 |
004 | #nginx进程数,建议设置为等于CPU总核心数。 |
005 | worker_processes 8; |
006 |
007 | #全局错误日志定义类型,[ debug | info | notice | warn | error | crit ] |
008 | error_log /var/log/nginx/error.log info; |
009 |
010 | #进程文件 |
011 | pid /var/run/nginx.pid; |
012 |
013 | #一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除,但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致。 |
014 | worker_rlimit_nofile 65535; |
015 |
016 | #工作模式与连接数上限 |
017 | events { |
018 |
019 | #参考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll模型是Linux 2.6以上版本内核中的高性能网络I/O模型,如果跑在FreeBSD上面,就用kqueue模型。 |
020 | use epoll; |
021 |
022 | #单个进程最大连接数(最大连接数=连接数*进程数) |
023 | worker_connections 65535; |
024 | } |
025 |
026 | #设定http服务器 |
027 | http { |
028 | include mime.types; #文件扩展名与文件类型映射表 |
029 | default_type application/octet-stream; #默认文件类型 |
030 | #charset utf-8; #默认编码 |
031 | server_names_hash_bucket_size 128; #服务器名字的hash表大小 |
032 | client_header_buffer_size 32k; #上传文件大小限制 |
033 | large_client_header_buffers 4 64k; #设定请求缓 |
034 | client_max_body_size 8m; #设定请求缓 |
035 | sendfile on; #开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。 |
036 | autoindex on; #开启目录列表访问,合适下载服务器,默认关闭。 |
037 | tcp_nopush on; #防止网络阻塞 |
038 | tcp_nodelay on; #防止网络阻塞 |
039 | keepalive_timeout 120; #长连接超时时间,单位是秒 |
040 |
041 | #FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。下面参数看字面意思都能理解。 |
042 | fastcgi_connect_timeout 300; |
043 | fastcgi_send_timeout 300; |
044 | fastcgi_read_timeout 300; |
045 | fastcgi_buffer_size 64k; |
046 | fastcgi_buffers 4 64k; |
047 | fastcgi_busy_buffers_size 128k; |
048 | fastcgi_temp_file_write_size 128k; |
049 |
050 | #gzip模块设置 |
051 | gzip on; #开启gzip压缩输出 |
052 | gzip_min_length 1k; #最小压缩文件大小 |
053 | gzip_buffers 4 16k; #压缩缓冲区 |
054 | gzip_http_version 1.0; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0) |
055 | gzip_comp_level 2; #压缩等级 |
056 | gzip_types text/plain application/x-javascript text/css application/xml; |
057 |
058 | #压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。 |
059 | gzip_vary on; |
060 | #limit_zone crawler $binary_remote_addr 10m; #开启限制IP连接数的时候需要使用 |
061 |
062 | upstream snsgou.com { |
063 | #upstream的负载均衡,weight是权重,可以根据机器配置定义权重。weigth参数表示权值,权值越高被分配到的几率越大。 |
064 | server 192.168.80.121:80 weight=3; |
065 | server 192.168.80.122:80 weight=2; |
066 | server 192.168.80.123:80 weight=3; |
067 | } |
068 |
069 | #虚拟主机的配置 |
070 | server { |
071 |
072 | #监听端口 |
073 | listen 80; |
074 |
075 | #域名可以有多个,用空格隔开 |
076 | server_name blog.snsgou.com snsgou.com; |
077 | index index.html index.htm index.php; |
078 | root /data/www/qianyunlai; |
079 |
080 | location ~ .*.(php|php5)?$ { |
081 | fastcgi_pass 127.0.0.1:9000; |
082 | fastcgi_index index.php; |
083 | include fastcgi.conf; |
084 | } |
085 |
086 | #图片缓存时间设置 |
087 | location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ { |
088 | expires 10d; |
089 | } |
090 |
091 | #JS和CSS缓存时间设置 |
092 | location ~ .*.(js|css)?$ { |
093 | expires 1h; |
094 | } |
095 |
096 | #日志格式设定 |
097 | log_format access '$remote_addr - $remote_user [$time_local] "$request" ' |
098 | '$status $body_bytes_sent "$http_referer" ' |
099 | '"$http_user_agent" $http_x_forwarded_for' ; |
100 |
101 | #定义本虚拟主机的访问日志 |
102 | access_log /var/log/nginx/qianyunlai.log access; |
103 |
104 | #对 "/" 启用反向代理 |
105 | location / { |
106 | proxy_pass http://127.0.0.1:88;[/code] |
107 | proxy_redirect off; |
108 | proxy_set_header X-Real-IP $remote_addr; |
109 |
110 | #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP |
111 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
112 |
113 | #以下是一些反向代理的配置,可选。 |
114 | proxy_set_header Host $host; |
115 | client_max_body_size 10m; #允许客户端请求的最大单文件字节数 |
116 | client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数, |
117 | proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间(代理连接超时) |
118 | proxy_send_timeout 90; #后端服务器数据回传时间(代理发送超时) |
119 | proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时) |
120 | proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小 |
121 | proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的设置 |
122 | proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2) |
123 | proxy_temp_file_write_size 64k; |
124 | #设定缓存文件夹大小,大于这个值,将从upstream服务器传 |
125 | } |
126 |
127 | #设定查看Nginx状态的地址 |
128 | location /NginxStatus { |
129 | stub_status on; |
130 | access_log on; |
131 | auth_basic "NginxStatus" ; |
132 | auth_basic_user_file conf/htpasswd; |
133 | #htpasswd文件的内容可以用apache提供的htpasswd工具来产生。 |
134 | } |
135 |
136 | #本地动静分离反向代理配置 |
137 | #所有jsp的页面均交由tomcat或resin处理 |
138 | location ~ .(jsp|jspx| do )?$ { |
139 | proxy_set_header Host $host; |
140 | proxy_set_header X-Real-IP $remote_addr; |
141 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
142 | proxy_pass http://127.0.0.1:8080;[/code] |
143 | } |
144 |
145 | #所有静态文件由nginx直接读取不经过tomcat或resin |
146 | location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ { |
147 | expires 15d; |
148 | } |
149 |
150 | location ~ .*.(js|css)?$ { |
151 | expires 1h; |
152 | } |
153 | } |
154 | } |
相关文章推荐
- (总结)Nginx配置文件nginx.conf中文详解
- (总结)Nginx配置文件nginx.conf中文详解(转自:http://www.ha97.com/5194.html)
- Nginx配置文件nginx.conf中文详解
- Nginx配置文件nginx.conf中文详解
- Nginx配置文件nginx.conf中文详解
- (总结)Nginx配置文件nginx.conf中文详解
- Nginx配置文件nginx.conf中文详解
- 经典-Nginx配置文件nginx.conf中文详解
- (总结)Nginx配置文件nginx.conf中文详解
- (总结)Nginx配置文件nginx.conf中文详解
- Nginx配置文件nginx.conf中文详解总结及nginx无缝升级
- (总结)Nginx配置文件nginx.conf中文详解(转)
- Nginx配置文件nginx.conf中文详解
- (总结)Nginx配置文件nginx.conf中文详解
- Nginx配置文件nginx.conf中文详解
- Nginx配置文件nginx.conf中文详解
- Nginx配置文件nginx.conf中文详解
- (总结)Nginx配置文件nginx.conf中文详解
- Nginx配置文件nginx.conf中文详解(总结)
- Nginx配置文件nginx.conf中文详解