forked from ninuxGithub/spring-boot-vue-separate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.conf
150 lines (130 loc) · 5.56 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#Nginx所用用户和组,window下不指定
#user niumd niumd;
#工作的子进程数量(通常等于CPU数量或者2倍于CPU)
worker_processes 2;
#错误日志存放路径
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
#指定pid存放文件
pid logs/nginx.pid;
events {
#使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。
#use epoll;
#允许最大连接数
worker_connections 1024;
}
http {
#文件扩展名与文件类型映射表
include mime.types;
#默认文件类型
default_type application/octet-stream;
#默认编码
charset utf-8;
#定义日志格式
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for $request_time $upstream_response_time $upstream_addr $upstream_status"';
###############日志参数的意思对应表#######################################################
#$remote_addr 与$http_x_forwarded_for 用以记录客户端的ip地址;
#$remote_user :用来记录客户端用户名称;
#$time_local :用来记录访问时间与时区;
#$request :用来记录请求的url与http协议;
#$status :用来记录请求状态;
#$body_bytes_sent :记录发送给客户端文件主体内容大小;
#$http_referer :用来记录从那个页面链接访问过来的;
#$http_user_agent :记录客户端浏览器的相关信息;。
#$request_time :响应数据的时间
#$upstream_response_time: 是指从Nginx向后端(php-cgi)建立连接开始到接受完数据然后关闭连接为止的时间。
#$upstream_addr: 后台upstream的地址,即真正提供服务的主机地址
#access_log off;
access_log logs/access.log main;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
#分页大小可以用命令getconf PAGESIZE 取得。
#但也有client_header_buffer_size超过4k的情况,但是client_header_buffer_size该值必须设置为“系统分页大小”的整倍数。
client_header_buffer_size 32k;
#客户请求头缓冲大小。nginx默认会用client_header_buffer_size这个buffer来读取header值,如果header过大,它会使用large_client_header_buffers来读取。
large_client_header_buffers 4 64k;
#sendfile指令指定 nginx 是否调用sendfile 函数(zero copy 方式)来输出文件,对于普通应用,必须设为on。如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络IO处理速度,降低系统uptime。
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 75 20;
#gzip配置
include gzip.conf;
#负载均衡配置
upstream proxy_server {
#根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能。
#ip_hash;#同一机器在多网情况下,路由切换,ip可能不同, ip_hash 不支持backup
server localhost:8000 weight=4 max_fails=2 fail_timeout=30s;
server localhost:9000 weight=6 max_fails=2 fail_timeout=30s;
server localhost:8888 backup;
keepalive 300;
}
#访问nginx自带的页面nginx首页地址:http://www.nginxserver.com:8080/
server {
listen 8080;
server_name www.nginxserver.com;
index index.html index.htm;
root html;
location ~ .*\.(html|htm)?$ {
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
expires 30s;
}
#expires 30s; //表示把数据缓存30秒
#expires 30m;//表示把数据缓存30分
#expires 10h;//表示把数据缓存10小时
#expires 1d;//表示把数据缓存1天
location ~ .*\.(js|css)?$ {
expires 30s;
}
}
#通过代理访问后台的服务器:http://www.nginxserver.com/
server {
listen 80;
server_name www.nginxserver.com;
index index.html index.htm;
root html;
location / {
proxy_pass http://proxy_server;
#proxy config
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_http_version 1.1;
}
#设定查看Nginx状态的地址
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus Login";
#https://www.cnblogs.com/AloneSword/p/5086918.html
auth_basic_user_file htpasswd;#htpasswd文件的内容可以用apache提供的htpasswd工具来产生。
allow 127.0.0.1; # 白名单
allow 10.1.51.96; # 白名单
deny all; #禁止其他的地址访问
}
#加入了一下配置后,既可以通过8080端口访问nginx的首页, 也可以通过80端口访问nginx首页
location ~ .*\.(html|htm)?$ {
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
expires 30s;
}
location ~ .*\.(js|css)?$ {
expires 30s;
}
}
}