Nginx正则表达式没有正确匹配

时间:2018-04-10 06:47:02

标签: nginx

我有一个非常基本的nginx/nginx.conf但不幸的是我无法让1台服务器正常匹配,我很确定它是因为它们使用了一些与其他域

完全相同的文本

我已经在regex101.com上测试了正则表达式,它们似乎与它们应该的方式相匹配,但是nginx正在与它们做其他事情

这就是我的整个nginx conf看起来像

https://pastebin.com/E3N8awGk

关键领域:

# lopudesigns
    server {
        listen  80;
        server_name     ~^(.*|)(\.|)lopudesigns\.dev$;
        keepalive_timeout   70;

        location / {
            proxy_set_header  x-real-IP             $remote_addr;
            proxy_set_header  x-forwarded-for       $proxy_add_x_forwarded_for;
            proxy_http_version  1.1;
            # proxy_set_header    Upgrade                 $http_upgrade;
            # proxy_set_header    Connection              $connection_upgrade;
            proxy_set_header    host                    $host;
            proxy_pass          http://127.0.0.1:7777;
        }
    }
    # lopudesigns example sites
    server {
        listen  80;
        server_name     ~^ozledgrowlights\.lopudesigns\.dev$;
        keepalive_timeout   70;

        location / {
            proxy_set_header  x-real-IP             $remote_addr;
            proxy_set_header  x-forwarded-for       $proxy_add_x_forwarded_for;
            proxy_http_version  1.1;
            # proxy_set_header    Upgrade                 $http_upgrade;
            # proxy_set_header    Connection              $connection_upgrade;
            proxy_set_header    host                    $host;
            proxy_pass          http://127.0.0.1:1337;
        }
    }
    # ozledgrowlights
    server {
        listen  80;
        server_name     ~^(.*|)(\.|)ozledgrowlights\.dev\.au$;
        keepalive_timeout   70;

        location / {
            proxy_set_header  x-real-IP             $remote_addr;
            proxy_set_header  x-forwarded-for       $proxy_add_x_forwarded_for;
            proxy_http_version  1.1;
            # proxy_set_header    Upgrade                 $http_upgrade;
            # proxy_set_header    Connection              $connection_upgrade;
            proxy_set_header    host                    $host;
            proxy_pass          http://127.0.0.1:1337;
        }
    }
    # a lopu client
    server {
        listen               80;
        server_name         ~^(.*|)(\.|)alopu\.com$;
        return 301          https://$server_name$request_uri;
    }
    server {
        listen              443 ssl;
        server_name         ~^(.*|)(\.|)alopu\.com$;
        keepalive_timeout   70;
        location / {
            proxy_set_header  x-real-IP             $remote_addr;
            proxy_set_header  x-forwarded-for       $proxy_add_x_forwarded_for;
            proxy_http_version  1.1;
            proxy_set_header    Upgrade                 $http_upgrade;
            proxy_set_header    Connection              $connection_upgrade;
            proxy_set_header    host                    $host;
            proxy_pass          http://127.0.0.1:8888;
        }
        ssl_certificate         /usr/local/etc/nginx/certs/alopu/server.crt.pem;
        ssl_certificate_key     /usr/local/etc/nginx/certs/alopu/server.key.pem;
        ssl_session_cache       shared:SSL:10m;
        ssl_session_timeout     10m;

    }

ozledgrowlights.dev.au正确匹配

alopu.com正确匹配

但是lopudesigns.dev代理到http://127.0.0.1:8888代替http://127.0.0.1:7777

这很明显,因为网址没有变化,所以它实际上并没有被重定向到alopu.com,这意味着alopu.com正则表达式/服务器块正在捕获那些http请求,这是自正则表达式以来非常奇怪

~^(.*|)(\.|)lopudesigns\.dev$;完全捕获lopudesigns.dev~^(.*|)(\.|)alopu\.com$;完全捕获lopudesigns.dev

我还应该注意~^(.*|)(\.|)ozledgrowlights\.dev\.au$;根本没有捕获任何内容,因此ozledgrowlights.lopudesigns.dev根本不会加载任何内容

所以我有点困惑? :o

1 个答案:

答案 0 :(得分:0)

抱歉,这是.dev域名的一些本地问题,不确定它是什么,但将.dev更改为.ved使其工作...奇怪