第十六篇 nginx主配置文件参数解释

  1 # 指定拥有运行nginx权限的用户
  2 #user  nobody;   
  3 
  4 # 指定开启的进程数,建议设置为CPU核心数
  5 worker_processes  1;  
  6 
  7 # 指定全局错误日志级别,包括:debug/info/notice/warn/error/crit
  8 #error_log  logs/error.log;
  9 #error_log  logs/error.log  notice;
 10 #error_log  logs/error.log  info;
 11 
 12 # 指定nginx的主进程id的存储位置
 13 pid        logs/nginx.pid;
 14 
 15 # 一个nginx进程最多能打开的文件描述符数目,理论上应该等于系统最多能打开的文件数与nginx进程数相除
 16 worker_rlimit_nofile 65535;
 17 
 18 
 19 
 20 events {
 21     
 22     # 指定工作模式
 23     # epoll使Linux2.6以上版本的高性能网络I/O模型
 24     # 如果跑在FreeBSD上面,使用kqueue模型
 25     use  epoll;
 26 
 27     # 指定每个进程的最大连接数,受系统进程的最大打开文件数量限制
 28     worker_connections  1024;
 29 }
 30 
 31 
 32 
 33 # 配置http服务器
 34 http {
 35     # 文件扩展名与文件类型映射表
 36     include       mime.types;
 37 
 38     # 指定默认文件类型,这里设置为二进制流
 39     default_type  application/octet-stream;
 40     
 41     # 指定默认编码
 42     #charset  utf-8;
 43 
 44     # 指定服务器名字的hash表大小
 45     #server_name_hash_bucket_size  128;
 46 
 47     # 指定允许客户端请求的最大单个文件字节数
 48     #client_max_body_size  20M;
 49 
 50     # 指定客户端请求头的headerbuffer大小
 51     #client_header_buffer_size  32k;
 52     
 53     # 指定客户端请求试图写入缓存文件的目录路径
 54     #client_body_temp_path  /dev/shm/client_body_temp;
 55 
 56     # 指定客户端请求中较大的消息头的缓存最大数量和大小
 57     #large client_header_buffers 4 32k;
 58 
 59     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 60     #                  '$status $body_bytes_sent "$http_referer" '
 61     #                  '"$http_user_agent" "$http_x_forwarded_for"';
 62 
 63     #access_log  logs/access.log  main;
 64 
 65     # 开启高效文件传输模式
 66     sendfile        on;
 67     # 开启防止网络阻塞
 68     tcp_nopush     on;
 69     # 开启防止网络阻塞
 70     tcp_nodely     on;
 71 
 72     # 指定连接超时时间,单位是秒
 73     #keepalive_timeout  0;
 74     keepalive_timeout  65;
 75     # 指定读取请求header超时时间
 76     #client_header_timeout  10;
 77     # 指定读取请求body超时时间
 78     #client_body_timeout  20;
 79 
 80     
 81     # http的gzip模块配置
 82 
 83     # 开启gzip压缩    
 84     #gzip  on;
 85 
 86     # 指定最小压缩文件大小
 87     #gzip_min_length  1k;
 88 
 89     # 申请4个大小为16k的内存空间作为压缩缓冲区
 90     #gzip_buffers 4 16k;
 91 
 92     # 设置识别http协议的版本,默认为1.1
 93     #gzip_http_version 1.1
 94 
 95     # 指定gzip压缩比,1-9,数字越小压缩比越小,压缩速度越快
 96     #gzip_comp_level 2;
 97 
 98     # 指定压缩类型
 99     # 默认已包含text/html,如果再次指定,会有一个warn
100     #gzip_type text/plain application/x-javascript text/css application/xml;
101 
102     #gzip_vary  on;
103 
104 
105     # upstream用于实现负载均衡
106     # weight表示权重,值越大分配到的几率越大
107     upstream fisher {
108         server 127.0.0.1:5001 weight=2;
109         server 127.0.0.1:5002 weight=3;
110         server 127.0.0.1:5003 weight=4;
111     }
112 
113 
114     # 虚拟主机配置
115     server {
116 
117         # 指定监听端口
118         listen       80;
119 
120         # 指定域名,若有多个,用空格隔开
121         server_name  localhost;
122         
123         # 指定编码
124         #charset koi8-r;
125         
126         # 指定虚拟主机访问日志的存放路径,日志格式为main
127         #access_log  logs/host.access.log  main;
128 
129         # 配置虚拟主机的基本信息
130         location / {
131             # 设置虚拟主机的网站根目录
132             root   html;
133             # 设置虚拟主机默认访问的网页
134             index  index.html index.htm;
135             proxy_pass http://fisher;
136         }
137 
138         #error_page  404              /404.html;
139 
140         # redirect server error pages to the static page /50x.html
141         #
142         error_page   500 502 503 504  /50x.html;
143         location = /50x.html {
144             root   html;
145         }
146 
147         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
148         #
149         #location ~ \.php$ {
150         #    proxy_pass   http://127.0.0.1;
151         #}
152 
153         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
154         #
155         #location ~ \.php$ {
156         #    root           html;
157         #    fastcgi_pass   127.0.0.1:9000;
158         #    fastcgi_index  index.php;
159         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
160         #    include        fastcgi_params;
161         #}
162 
163         # deny access to .htaccess files, if Apache's document root
164         # concurs with nginx's one
165         #
166         #location ~ /\.ht {
167         #    deny  all;
168         #}
169     }
170 
171 
172     # another virtual host using mix of IP-, name-, and port-based configuration
173     #
174     #server {
175     #    listen       8000;
176     #    listen       somename:8080;
177     #    server_name  somename  alias  another.alias;
178 
179     #    location / {
180     #        root   html;
181     #        index  index.html index.htm;
182     #    }
183     #}
184 
185 
186     # HTTPS server
187     #
188     #server {
189     #    listen       443 ssl;
190     #    server_name  localhost;
191 
192     #    ssl_certificate      cert.pem;
193     #    ssl_certificate_key  cert.key;
194 
195     #    ssl_session_cache    shared:SSL:1m;
196     #    ssl_session_timeout  5m;
197 
198     #    ssl_ciphers  HIGH:!aNULL:!MD5;
199     #    ssl_prefer_server_ciphers  on;
200 
201     #    location / {
202     #        root   html;
203     #        index  index.html index.htm;
204     #    }
205     #}
206 
207 }

猜你喜欢

转载自www.cnblogs.com/xuezou/p/9190789.html
今日推荐