当前位置:首页 > 服务器技术 > nginx

第十六篇 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 20events {
 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服务器
 34http {
 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;
101102    #gzip_vary  on;
103104105    # 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    }
112113114    # 虚拟主机配置
115    server {
116117        # 指定监听端口
118         listen       80;
119120        # 指定域名,若有多个,用空格隔开
121        server_name  localhost;
122123        # 指定编码
124         #charset koi8-r;
125126        # 指定虚拟主机访问日志的存放路径,日志格式为main
127         #access_log  logs/host.access.log  main;
128129        # 配置虚拟主机的基本信息
130         location / {
131            # 设置虚拟主机的网站根目录
132            root   html;
133            # 设置虚拟主机默认访问的网页
134            index  index.html index.htm;
135             proxy_pass http://fisher;136        }
137138         #error_page  404              /404.html;
139140         # redirect server error pages to the static page /50x.html
141        #
142         error_page   500502503504  /50x.html;
143         location = /50x.html {
144            root   html;
145        }
146147         # proxy the PHP scripts to Apache listening on 127.0.0.1:80148        #
149         #location ~ .php$ {
150         #    proxy_pass   http://127.0.0.1;151        #}
152153         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000154        #
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        #}
162163         # deny access to .htaccess files, if Apaches document root164         # concurs with nginxs one165        #
166         #location ~ /.ht {
167        #    deny  all;
168        #}
169    }
170171172     # 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;
178179     #    location / {
180    #        root   html;
181    #        index  index.html index.htm;
182    #    }
183    #}
184185186    # HTTPS server
187    #
188    #server {
189     #    listen       443 ssl;
190    #    server_name  localhost;
191192    #    ssl_certificate      cert.pem;
193    #    ssl_certificate_key  cert.key;
194195    #    ssl_session_cache    shared:SSL:1m;
196    #    ssl_session_timeout  5m;
197198     #    ssl_ciphers  HIGH:!aNULL:!MD5;
199    #    ssl_prefer_server_ciphers  on;
200201     #    location / {
202    #        root   html;
203    #        index  index.html index.htm;
204    #    }
205    #}
206207 }

 

原文:https://www.cnblogs.com/xuezou/p/9190789.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!