NGINX 不遵守 server_name 正则表达式
NGINX not respecting server_name regex
我有这个 nginx 配置..我希望它接受所有包含单词 competitions 并以 .com.au.. 结尾的域。我已经测试了一个不应被接受但它到达应用程序.. server_name 是否因为我使用代理而被忽略?
server {
listen 80 default_server;
server_name ~^(.+)competitions?(.+)\.com\.au;
access_log /var/log/nginx/$host.access.log;
error_log /var/log/nginx/error.log;
if ($host !~* ^www){
rewrite ^/(.*)$ https://www.$host/ permanent;
}
location / {
proxy_no_cache 1;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8888;
try_files $uri $uri/ @proxy;
}
location @proxy {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8888;
proxy_intercept_errors on;
recursive_error_pages on;
error_page 404 = @rewrite_proxy;
}
location @rewrite_proxy {
rewrite /(.*) /index.cfm?path=;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8888;
}
}
您必须从那里删除 default_server
,因为这是一个包罗万象的指令。
您仍然可以使用 [= 设置另一个 server
10=] 指令,如果需要的话。
查看How nginx processes a request更详细的解释:
If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port.
我有这个 nginx 配置..我希望它接受所有包含单词 competitions 并以 .com.au.. 结尾的域。我已经测试了一个不应被接受但它到达应用程序.. server_name 是否因为我使用代理而被忽略?
server {
listen 80 default_server;
server_name ~^(.+)competitions?(.+)\.com\.au;
access_log /var/log/nginx/$host.access.log;
error_log /var/log/nginx/error.log;
if ($host !~* ^www){
rewrite ^/(.*)$ https://www.$host/ permanent;
}
location / {
proxy_no_cache 1;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8888;
try_files $uri $uri/ @proxy;
}
location @proxy {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8888;
proxy_intercept_errors on;
recursive_error_pages on;
error_page 404 = @rewrite_proxy;
}
location @rewrite_proxy {
rewrite /(.*) /index.cfm?path=;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8888;
}
}
您必须从那里删除 default_server
,因为这是一个包罗万象的指令。
您仍然可以使用 [= 设置另一个 server
10=] 指令,如果需要的话。
查看How nginx processes a request更详细的解释:
If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port.