-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.conf
112 lines (97 loc) · 3.33 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
worker_processes 1;
# 错误日志目录
error_log logs/error.log error;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
# 主要的http配置
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr|$remote_user|[$time_local]|"$request"'
'|$status|$request_time|$body_bytes_sent|"$http_referer"'
'|"$http_user_agent"|"$http_x_forwarded_for"|"$upstream_response_time"|"$http_cookie"';
# 成功日志,正常日志
access_log logs/access.log main;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
# 开启gzip压缩
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/json;
gzip_vary on;
gzip_proxied any;
map $http_origin $corsDomain {
"~https://wyling.com" https://wyling.com;
"~https://horrylala.com" https://horrylala.com;
}
server {
listen 8080;
server_name localhost;
access_log logs/access.log main;
location / {
# 静态资源的主要目录
root /app/data/webroot;
index index.html index.htm;
error_page 405 =200 $uri;
try_files $uri $uri/ /index.html;
# 单页面应用的index.html不缓存
location = /index.html {
add_header Cache-Control "no-cache,no-store";
}
location ~* \.(css|js){
add_header Cache-Control "max-age=31536000";
}
}
# 开启一个子目录的服务,新开的单页面应用
location /dream {
alias /app/data/dream;
index index.html index.htm;
error_page 405 =200 $uri;
try_files $uri $uri/ /dream/index.html;
location = /dream/index.html {
add_header Cache-Control "no-cache,no-store";
}
location ~* \.(css|js){
add_header Cache-Control "max-age=31536000";
}
}
# 对应服务端暴露接口
location /api {
proxy_pass http://api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
index index.html index.jsp login.jsp index.htm;
proxy_intercept_errors on;
error_page 500 502 503 504 /error.html;
# limit_req zone=allips nodelay;
add_header 'Access-Control-Allow-Origin' $corsDomain;
# 跨域请求是,携带跨域请求的cookies
add_header 'Access-Control-Allow-Credentials' 'true';
# 允许的请求类型
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
# 允许的头类型
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# upstream映射,对应Nginx地址
upstream api {
# 轮询机制
ip_hash;
server xxx.xxx.xxx.xxx:8080;
server xxx.xxx.xxx.xxx:8080;
}
}