从这篇开始,我的文章需要写的尽可能的明了一些,在给自己带来记录价值的时候。也希望能被更多的人,看到和学习。
通过一步步的实践,来巩固自己的理论基础。也是写这篇文章的初衷。
基本架构
这里的架构是两层架构。
- 公有云上的服务器提供公网的接入
- 自家的一台服务器提供服务本体
关于两个服务器连接的方式,这里直接使用的是 wireguard 来进行 virtual network的组网的,所以两台主机在 网络层就已经是互通的了。
技术方案
使用nginx来做反向代理,主要是使用 7层的代理来进行转发。
这里为了实现多域名的转发功能,在dns 使用了泛解析配置
通过nginx配置来做到对所有的泛解析域名来进行规则转发。
配置代码 TL;DR
接入主机的 nginx 配置
location ^~ / {
auth_basic "Please input password";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
set $up_addr 10.77.77.4:80;
proxy_set_header x-real-ip $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
#proxy_set_header x-forwarded-for $remote_addr;
client_max_body_size 100m;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_pass http://$up_addr;
}
服务主机的 nginx 配置
location ^~ / {
if ($host = mcs.****.12ms.xyz) {
set $rule_hit 1;
set $up_addr 192.168.66.10:23333;
}
if ($host = router.****.12ms.xyz) {
set $rule_hit 1;
set $up_addr 192.168.66.1:80;
}
if ($host = ap.****.12ms.xyz) {
set $rule_hit 1;
set $up_addr 192.168.66.2:80;
}
if ($host = esxi.****.12ms.xyz) {
set $rule_hit 1;
set $up_addr 192.168.66.3:80;
}
if ($rule_hit != 1) {
set $up_addr 192.168.66.11:80;
}
proxy_set_header x-real-ip $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
client_max_body_size 100m;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_pass http://$up_addr;
}