Nginx

nginx 不會監聽 ipv6

  • July 16, 2015

我正在執行一個 nginx 伺服器(1.8.0),我想在 ipv4 和 ipv6 中收聽。但即使使用正確的監聽語句(當然還有 nginx 的重啟)也會 netstat -tlp | grep nginx返回

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

我嘗試了不同的監聽語句組合(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;
       }
   }
}

nginx 沒有正確重啟。我手動殺死了所有 nginx 程序並重新啟動了服務。

引用自:https://serverfault.com/questions/700957