-
Notifications
You must be signed in to change notification settings - Fork 1
/
nginx.example.conf
102 lines (82 loc) · 2.84 KB
/
nginx.example.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
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream go_app_main {
server 127.0.0.1:5000;
}
server {
listen 80;
server_tokens off;
#server_name localhost;
charset utf8;
#access_log logs/host.access.log main;
# 转发给 web 应用
location /login {
proxy_http_version 1.1; # 默认 HTTP 1.0
proxy_set_header Host $http_host; # 替换为真实 IP
proxy_redirect off;
proxy_pass https://go_app_main;
# nginx 拦截错误定义错误页面
proxy_intercept_errors on;
}
location /logout {
proxy_http_version 1.1;
proxy_set_header Host $http_host; # 替换为真实 IP
proxy_redirect off;
proxy_pass https://go_app_main;
# nginx 拦截错误定义错误页面
proxy_intercept_errors on;
}
location /api {
proxy_http_version 1.1;
proxy_set_header Host $http_host; # 替换为真实 IP
proxy_redirect off;
proxy_pass https://go_app_main;
# nginx 拦截错误定义错误页面
proxy_intercept_errors on;
}
location /websocket { # 反向代理 websocket
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass https://go_app_main;
}
set $nginx_dist_file /usr/share/nginx/dist;
set $nginx_media_file /usr/share/nginx/media;
location / {
root $nginx_dist_file;
}
# 存储用户上传的照片
location /media {
# 注意 root 和 alias 的 区别
# alias 给 url 起个别名
# root 是把 url 挂在 root 下,如 /$root/media
# 这里要用 media
alias $nginx_media_file;
}
error_page 404 /404.html;
location = /404.html {
# 放错误页面的目录路径。
root $nginx_dist_file;
}
}
}