![Nginx 捕获通配符子域名而不是精确子域名](https://linux22.com/image/733795/Nginx%20%E6%8D%95%E8%8E%B7%E9%80%9A%E9%85%8D%E7%AC%A6%E5%AD%90%E5%9F%9F%E5%90%8D%E8%80%8C%E4%B8%8D%E6%98%AF%E7%B2%BE%E7%A1%AE%E5%AD%90%E5%9F%9F%E5%90%8D.png)
我的 nginx 设置遇到了一些问题。
我正在尝试为另一个系统路径设置一个子域,但由于某种原因,nginx 重定向到一个捕获所有通配符而不是确切的通配符。
配置如下:
server {
listen 8080;
listen [::]:8080;
root /www/example.com/public;
index index.php index.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 8080;
listen [::]:8080;
root /www/example.com/public_static;
index index.html
server_name static.example.com;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 8080;
listen [::]:8080;
root /www/example.com/public;
server_name *.examlpe.com;
location / {
try_files $uri /nosub.html;
}
}
还有一个反向代理正在运行,其配置如下:
upstream internalservers {
server 127.0.0.1:8080;
}
server {
listen 80;
listen [::]:80;
listen 443;
listen [::]:443;
server_name _;
location / {
proxy_set_header Host $http_host;
proxy_pass http://internalservers;
}
}
server {
listen 8080;
listen [::]:8080;
root /www/default/
server_name _;
location / {
try_files $uri /nodomain.html;
}
}
当我尝试访问特定的子域(静态)时,它会重定向到定义的 catch-all 子域,因此我认为这不是代理设置中的问题。