【问题标题】:NGINX not respecting server_name regexNGINX 不尊重 server_name 正则表达式
【发布时间】:2020-12-30 07:31:10
【问题描述】:

我有这个 nginx 配置..我希望它接受所有包含单词竞争并以 .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/$1 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=$1;
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8888;
    }

}

【问题讨论】:

    标签: nginx-config


    【解决方案1】:

    您必须从那里删除default_server,因为这是一个包罗万象的指令。
    如果需要,您仍然可以使用default_server 指令设置另一个server

    更详细的解释见How nginx processes a request

    如果它的值不匹配任何服务器名称,或者请求根本不包含这个头域,那么 nginx 会将请求路由到这个端口的默认服务器。

    【讨论】:

    • 我删除了 default_server 并将其添加到顶级服务器 { listen 80 default_server;服务器名称 _; } 现在可以使用了.. 谢谢
    猜你喜欢
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 2013-03-12
    • 2016-10-21
    • 2016-12-20
    • 2017-05-05
    • 2018-07-18
    相关资源
    最近更新 更多