wodedatacom 上的 n
18 June 2023
wodedata.com 上的 Nginx Proxmy Manager 配置
http.config 配置 (官方说明: Custom Nginx Configurations)
以下使用 map 配置匹配 wodedata.com 的所有子域名 转发到 https://10.10.10.7:4443.
map $host $backend {
default https://10.10.10.7:4443;
~^(?<subdomain>.+)\.wodedata.com$ https://10.10.10.7:4443;
}
server {
listen 80;
listen [::]:80;
server_name *.wodedata.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name *.wodedata.com;
# Let's Encrypt SSL
include conf.d/include/letsencrypt-acme-challenge.conf;
include conf.d/include/ssl-ciphers.conf;
ssl_certificate /etc/letsencrypt/live/npm-3/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/npm-3/privkey.pem;
# Force SSL
include conf.d/include/force-ssl.conf;
access_log /data/logs/proxy-host-http_access.log proxy;
error_log /data/logs/proxy-host-http_error.log warn;
location / {
proxy_pass $backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
第一个 map 语句中,default 表示默认情况下所有的请求都会以 https://10.10.10.7:4443 为后端服务。正则表达式 ~^(?<subdomain>.+)\.wodedata.com$ 只匹配 wodedata.com 的所有子域名,并将子域名保存在 $subdomain 变量中。在 proxy_pass 配置中, $backend 变量会动态地选取实际的后端服务地址。
第二个 server 语句中,listen 80 为 http 请求监听端口,listen 443 ssl 为 https 请求监听端口。server_name wodedata.com *.wodedata.com 声明了要监听的域名,这里使用了通配符 * 能够匹配所有的子域名。
第二个 server 语句中的 location 块配置了具体的代理转发规则,将所有请求转发到 $backend 变量所指向的后端服务。proxy_set_header 配置用于将一些关键信息透传到后端服务中,以保证请求的完整性。
第一个 server 语句中,将所有的 http 请求都重定向到 https 请求,保证数据的安全性。

