0%

Nginx反向代理demo

Nginx 反向代理配置Demo

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
# http --> https
server {
listen 80;
server_name report.visualchina.com;
rewrite (.*) https://$host$request_uri; # 返回302
# return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name report.visualchina.com;

access_log /var/log/nginx/report.visualchina.com.log main;
error_log /var/log/nginx/report.visualchina.com.error.log;
ssl_certificate sslfile/visualchina.com-2022.pem; #证书路径
ssl_certificate_key sslfile/visualchina.com-2022.key;

location / {
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;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://172.16.99.184:37799;
client_max_body_size 10M;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
}

# 指访问域名根目录的话,后面添加 /webroot/decision/
if ($request_uri ~* "^/$") {
rewrite (.*) https://$host/webroot/decision/;
}
}

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
server {
listen 80;
server_name *.zhaohongye.com zhaohongye.com;
# return 301 https://$host$request_uri;
return 301 https://zhaohongye.com$request_uri;
}

server {
listen 443 ssl;
server_name zhaohongye.com www.zhaohongye.com;
access_log /var/log/nginx_zhy/nginx_zhy_access.log main;
error_log /var/log/nginx_zhy/nginx_zhy_error.log;

ssl_certificate sslfile/zhy/5444626_zhaohongye.com.pem;
ssl_certificate_key sslfile/zhy/5444626_zhaohongye.com.key;

error_page 404 500 502 503 504 /502.html;
location = /502.html {
proxy_pass http://geeksre.zhaohongye.com/nginx-error-html/502.html;
}

location /hwwebscan_verify.html {
root /data/GeekSRE;
index hwwebscan_verify.html;
}
location /report.html {
alias /usr/share/nginx/html/zhy_report.html;
}
location / {
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;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http:// https://;
proxy_pass http://127.0.0.1:4000;
client_max_body_size 10M;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_http_version 1.1;
proxy_request_buffering off;
}
}

server {
listen 80;
server_name *.ops.ren ops.ren;
access_log /var/log/nginx/zhy.log main;
error_log /var/log/nginx/zhy.error.log;

if ($request_uri != /) {
return 301 http://ops.ren/;
}

location / {
proxy_pass https://geeksre.zhaohongye.com/other-web-index-html/ops.ren.html;
}
}

server {
listen 80;
server_name *.ops.work ops.work;
access_log /var/log/nginx/zhy.log main;
error_log /var/log/nginx/zhy.error.log;

if ($request_uri != /) {
return 301 http://ops.work/;
}

location / {
proxy_pass https://geeksre.zhaohongye.com/other-web-index-html/ops.work.html;
}
}
server {
listen 80;
server_name virgo.pub *.virgo.pub;
access_log /var/log/nginx/zhy.log main;
error_log /var/log/nginx/zhy.error.log;

if ($request_uri != /) {
return 301 http://virgo.pub/;
}

location / {
proxy_pass https://geeksre.zhaohongye.com/other-web-index-html/virgo.pub.html;
}
}