nginx.conf 配置记录

  1 #user  nobody;
  2 
  3 #启动进程,通常设置成和cpu的数量相等
  4 worker_processes  1;
  5 
  6 #全局错误日志及PID文件
  7 #error_log  lognginxs/error.log;
  8 #error_log  logs/error.log  notice;
  9 #error_log  logs/error.log  info;
 10 #pid        logs/nginx.pid;
 11 
 12 
 13 #工作模式及连接数上限
 14 events {
 15     #单个后台worker process进程的最大并发链接数
 16     worker_connections  1024;
 17 
 18     # 并发总数是 worker_processes 和 worker_connections 的乘积
 19     # 即 max_clients = worker_processes * worker_connections
 20     # 在设置了反向代理的情况下,max_clients = worker_processes * worker_connections / 4  为什么
 21     # 为什么上面反向代理要除以4,应该说是一个经验值
 22     # 根据以上条件,正常情况下的Nginx Server可以应付的最大连接数为:4 * 8000 = 32000
 23     # worker_connections 值的设置跟物理内存大小有关
 24     # 因为并发受IO约束,max_clients的值须小于系统可以打开的最大文件数
 25     # 而系统可以打开的最大文件数和内存大小成正比,一般1GB内存的机器上可以打开的文件数大约是10万左右
 26     # 我们来看看360M内存的VPS可以打开的文件句柄数是多少:
 27     # $ cat /proc/sys/fs/file-max
 28     # 输出 34336
 29     # 32000 < 34336,即并发连接总数小于系统可以打开的文件句柄总数,这样就在操作系统可以承受的范围之内
 30     # 所以,worker_connections 的值需根据 worker_processes 进程数目和系统可以打开的最大文件总数进行适当地进行设置
 31     # 使得并发总数小于操作系统可以打开的最大文件数目
 32     # 其实质也就是根据主机的物理CPU和内存进行配置
 33     # 当然,理论上的并发总数可能会和实际有所偏差,因为主机还有其他的工作进程需要消耗系统资源。
 34     # ulimit -SHn 65535
 35 }
 36 
 37 
 38 http {
 39     #设定mime类型,类型由mime.type文件定义
 40     include       mime.types;
 41 
 42     #默认返回数据的类型
 43     default_type  application/octet-stream;
 44 
 45     #设定日志格式
 46     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 47     #                  '$status $body_bytes_sent "$http_referer" '
 48     #                  '"$http_user_agent" "$http_x_forwarded_for"';
 49 
 50     #访问日志
 51     #access_log  logs/access.log  main;
 52 
 53     #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
 54     #对于普通应用,必须设为 on,
 55     #如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,
 56     #以平衡磁盘与网络I/O处理速度,降低系统的uptime.
 57     sendfile        on;
 58 
 59     #缓冲区中的数据立即发送出去
 60     #tcp_nopush     on;
 61 
 62     #一个请求完成之后还要保持连接的时间
 63     keepalive_timeout  65;
 64 
 65     #开启压缩
 66     #gzip  on;
 67 
 68     #发送数据的最大限制(上传文件用)
 69     client_max_body_size 20M;
 70 
 71     #设定虚拟主机配置
 72     server {
 73         #侦听80端口
 74         listen       80;
 75 
 76         #监听域名
 77         server_name  127.0.0.1;
 78 
 79         #字符编码
 80         #charset koi8-r;
 81 
 82         #访问日志
 83         #access_log  logs/host.access.log  main;
 84 
 85         #配置根目录
 86         location / {
 87             #指向目录
 88             root   E:/develop/logistics_s/logistics_cms/;
 89             #首页
 90             index  index.html index.htm;
 91         }
 92 
 93 
 94         #404
 95         #error_page  404              /404.html;
 96 
 97         #500 502 503 504
 98         error_page   500 502 503 504  /50x.html;
 99 
100         #50x.html
101         location = /50x.html {
102             root   html;
103         }
104 
105         #动态api接口
106         location /api/ {
107             proxy_redirect false;
108             proxy_set_header Host $host;
109             proxy_set_header X-Real-IP $remote_addr;
110             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
111             #动态代理地址
112             proxy_pass http://127.0.0.1:8083/;
113         }
114 
115         #静态代理
116         location /static/{
117             # 代理地址
118             alias  E:/var/www/html/upload/;
119             autoindex on;
120         }
121 
122     }
123 
124     #静态服务器
125     server {
126         listen       8888;
127         server_name  127.0.0.1;
128         charset utf-8;
129         # 添加请求头,解除跨域
130         add_header 'Access-Control-Allow-Origin' '*';
131         location /static/{
132             alias  E:/develop/lixingwu/src/main/resources/static/;
133             autoindex on;
134         }
135     }
136 
137     #静态html访问服务
138     server {
139         listen       9999;
140         server_name  127.0.0.1;
141         charset utf-8;
142         location /p/{
143             alias  E:/prototype/;
144             autoindex on;
145         }
146     }
147 
148 }

 

posted @ 2018-11-16 11:36  喵喵扑  阅读(250)  评论(0编辑  收藏  举报