forked from adams549659584/go-proxy-bingai
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
反向代理
zklcdc edited this page Feb 7, 2024
·
6 revisions
在宝塔的"网站",添加站点并添加已解析好的域名。
图片中的
example.com
换成自己的域名
在宝塔的"网站",点击“刚添加的域名”,点击“SSL”,然后点击“Let's Encrypt”申请证书,选择“强制https”,“保存”。
- 点击
网站
; - 点击
example.com
(替换为自己的域名); - 点击
SSL
; - 点击
Let's Encrypt
, 然后申请证书; - 选择
强制https
; - 点击保存
- 点击
网站
; - 点击
example.com
(替换为自己的域名); - 点击
配置文件
- 添加图中内容在
server
块之上
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
map $remote_addr $proxy_forwarded_elem {
# IPv4 addresses can be sent as-is
~^[0-9.]+$ "for=$remote_addr";
# IPv6 addresses need to be bracketed and quoted
~^[0-9A-Fa-f:.]+$ "for=\"[$remote_addr]\"";
# Unix domain socket names cannot be represented in RFC 7239 syntax
default "for=unknown";
}
map $http_forwarded $proxy_add_forwarded {
default "$proxy_forwarded_elem";
}
- 点击
网站
; - 点击
example.com
(替换为自己的域名); - 点击
反向代理
; - 点击
添加反向代理
; -
目标URL
输入http://127.0.0.1:8080
, (即你部署的地址和端口); - 点击保存
- 点击配置文件
- 全选删除后输入以下内容
location / {
proxy_pass http://127.0.0.1:8080; # 你部署的地址和端口
proxy_http_version 1.1;
# proxy_cache_bypass $http_upgrade;
# Proxy headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Forwarded $proxy_add_forwarded;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
# Proxy timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
- 点击保存即可