版本:nginx/1.2.0 || (我知道风险,它用于内部服务器)我将如何设置一个系统,17.hostname.com
将其放置为 proxy_pass http://192.168.56.17:80
(其中 17 将被替换为主机名之前的任何数字)
server_name ~^(?<subnum>[0-9]+)\.hostname\.com$;
proxy_pass http://192.168.56.$subnum;
Run Code Online (Sandbox Code Playgroud)
http://nginx.org/en/docs/http/server_names.html
map $host $backend {
default 1;
~*^(?P<number>[0-9]+)\.hostname\.com$ $number;
# FIXME: [0-9]+ must be replaced to regex with accurate check 1..254 range
# for example [1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4] or similar
}
server {
server_name *.hostname.com;
location / {
proxy_pass http://192.168.56.$backend:80;
}
}
Run Code Online (Sandbox Code Playgroud)
并记住:如果是邪恶的!!!;-)