nginx 不会监听 ipv6

nginx 不会监听 ipv6

我正在运行一个 nginx 服务器 (1.8.0),我想在 ipv4 和 ipv6 中监听。但即使使用了正确的 listen 语句(当然还要重启 nginx),也会 netstat -tlp | grep nginx返回

tcp        0      0 *:http                  *:*                     LISTEN      24720/nginx -g daem
tcp        0      0 *:https                 *:*                     LISTEN      24720/nginx -g daem

我尝试过不同的 listen 语句组合(ipv6only=off,只有 [::]:443)?

我错过了什么?

这是我的配置:

upstream foo {
    server localhost:8000;
}

server {
    listen        80;
    listen        [::]:80;
    server_name   www.foo.net foo.net foo.com www.foo.com;
    rewrite       ^ https://www.foo.com$request_uri? permanent;
}

server {
    listen        443 ssl spdy;
    listen        [::]:443 ssl spdy;
    server_name   www.foo.net foo.com;

    include       snippets/ssl.conf;

    return        301 https://www.foo.com$request_uri;
}

server {
    listen                       443 ssl spdy;
    listen                       [::]:443 ssl spdy;
    server_name                  www.foo.com *.foo.com;
    client_body_buffer_size      10k;
    client_header_buffer_size    1k;
    client_max_body_size         150M;
    large_client_header_buffers  2 32k;

    keepalive_timeout            70;

    include                     snippets/ssl.conf;
    include                     snippets/gzip.conf;

    access_log                  /var/logs/nginx/foo.access.log;
    error_log                   /var/logs/nginx/foo.error.log;


    location /static {
        aio threads;
        alias /srv/foo/static;
        expires max;
        add_header Cache-Control public;
        include confs/cors.conf;
        access_log on;
    }

    location / {
        proxy_redirect      off;
        proxy_set_header    Host                 $host;
        proxy_set_header    X-Real-IP            $remote_addr;
        proxy_set_header    X-Forwarded-For      $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Host     $host;
        proxy_set_header    X-Forwarded-Protocol ssl;
        proxy_set_header    X-Forwarded-Proto    $scheme;
        proxy_set_header    X-Forwarded-Ssl      on;
        proxy_set_header    Referer              $http_referer;
        add_header          Cache-Control        private;

        set $prerender 0;
        if ($http_user_agent ~* "baiduspider|bingbot|bingpreview|bitlybot|changedetection|daumoa|docomo|duckduckbot|embedly|exabot|ezooms|facebookexternalhit|googlebot|googlebot-mobile|ia_archiver|linkedinbot|magpie-crawler|metajobbot|mj12bot|msnbot|naverbot|netseer|outbrain|pinterest|proximic|quora link preview|rogerbot|seznambot|showyoubot|slackbot|spbot|tweetmemebot|twikle|twitterbot|yahoo|yahooseeker|yandexbot") {
            set $prerender 1;
        }

        if ($args ~ "_escaped_fragment_") {
             set $prerender 1;
        }

        if ($http_user_agent ~ "Prerender") {
            set $prerender 0;
        }

        if ($uri ~ "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent)") {
            set $prerender 0;
        }

        resolver 8.8.8.8;

        if ($prerender = 1) {
            rewrite .* /$scheme://$host$request_uri? break;
            proxy_pass https://prerender.foo.com;
        }

        if ($prerender = 0) {
            proxy_pass http://foo;
        }
    }
}

答案1

nginx 无法正常重启。我手动终止了所有 nginx 进程并重启了服务。

相关内容