2
0
热心网友
域名的泛域名解析
nginx可以直接做泛域名解析
server { listen 80; server_name *.edu.qumogu.com location / { root /data/www/test/; index index index.html; }
需要使用nginx的正则
需要使用nginx的判断if
# 示例一 if ($host !~* "^[a-zA-Z0-9_]{3,10}\.test\.domain\.com$") { return 444; } # 示例二 if ($host ~* ^newhouse\.(.+)?\.house365\.com) { set $host_city $1; rewrite ^(.*)$ http://$host_city.house365.com$1 permanent; }
需要使用nginx的变量,例如,下面的泛域名解析
server_name ~^(?<subdomain>.+)\.test\.domain\.com$; if ($subdomain !~* "^[a-zA-Z0-9]{3,10}$") { return 444; }
需要使用nginx的return
server { listen 80; if ($host !~* "^[a-zA-Z0-9_]{3,10}\.test\.domain\.com$") { return 444; } location / { root /data/www/test/; index index index.html; } }
server { listen 80; server_name ~^(?<subdomain>.+)\.test\.domain\.com$; if ($subdomain !~* "^[a-zA-Z0-9]{3,10}$") { return 444; } location / { root /data/www/test/; index index index.html; } }
实现1的时候,因为没有看过网上有加双引号的案例,所以不敢加 $host !~* ^[a-zA-Z0-9_]{3,10}\.test\.domain\.com$ 一直报错,一度怀疑nginx是否支持长度的判断
server_name ~ "^[a-zA-Z0-9_]{3,6}\.test\.domain\.com$";一直报server_name不是以;为结束的错误
使用道具 舉報
本版積分規則 發表回覆 回帖並轉播 回帖後跳轉到最後一頁
相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com
Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.