-
Notifications
You must be signed in to change notification settings - Fork 15
/
nginx.conf
89 lines (86 loc) · 3.31 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
# Copyright 2019-2020 Axetroy. All rights reserved. Apache License 2.0.
user nginx;
worker_processes auto; # CPU 核心数
# error_log /dev/null;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
multi_accept on;
worker_connections 65535;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log off;
sendfile on;
tcp_nopush on; # 告诉nginx在一个数据包里发送所有头文件,而不一个接一个的发送
gzip on;
gzip_min_length 1024; # 对数据启用压缩的最少字节数,如:请求小于1K文件,不要压缩,压缩小数据会降低处理此请求的所有进程速度
gzip_comp_level 7; # gzip压缩等级在0-9内,数值越大压缩率越高,CPU消耗也就越大
gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json image/jpeg image/gif image/png;
gzip_vary on;# varyheader支持,让前端的缓存服务器识别压缩后的文件,代理
server_tokens off; # Nginx打开网页报错时,关闭版本号显示
keepalive_timeout 75; # HTTP连接持续时间,值越大无用的线程变的越多,0:关闭此功能,默认为75
reset_timedout_connection on; # 告诉nginx关闭不响应的客户端连接
client_max_body_size 8m;
add_header X-Content-Type-Options nosniff;
upstream web {
ip_hash;
server frontend weight=1;
}
upstream api {
ip_hash;
server backend weight=1;
keepalive 300;
}
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 10m;
# websocket
location ~^/v1/shell/connect {
client_max_body_size 10m;
proxy_pass http://api;
proxy_set_header Accept */*;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
}
location ~^/v1 {
client_max_body_size 10m;
proxy_pass http://api;
proxy_set_header Accept */*;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Connection "keep-alive";
proxy_http_version 1.1;
}
location / {
client_max_body_size 1m;
if ( $request_method !~ ^GET$ ) {
add_header Allow "GET" always;
return 405;
}
proxy_pass http://web;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
location = /50x.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
}
}