Nginx:非www网站无法通过SSL(连接被拒绝)

我试图使用Ubuntu 14.04上的nginx来获得SSL安全的站点。

这是我的服务器块文件的样子:

server { listen 80; listen [::]:80; server_name example.com www.example.com; return 301 https://www.example.com$request_uri; } server { listen 443 ssl; listen [::]:443 ssl; server_name example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; return 301 https://www.example.com$request_uri; } server { listen 443 ssl; listen [::]:443 ssl; server_name www.example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; root /var/www/html; index index.php; location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { log_not_found off; access_log off; allow all; } location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ { expires max; log_not_found off; } location / { #try_files $uri $uri/ =404; #index index.php index.html index.htm index.nginx-debian.html; try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location ~ /\.ht { deny all; } location ~ /.well-known { allow all; } } 

第三块是用https服务wwwurl的“主”块(工作正常)。 第一个块将任何http和非www请求redirect到第三个块(工作正常)。

第二个块不起作用。 我试图在这里实现的是直接任何https和非www请求到第三块,但试图访问该网站这种方式产生“example.com拒绝连接”(与Chrome调用ERR_CONNECTION_REFUSED不同的是没有错误显示在请求的networking标签中,它只是一个空的请求)。

我已经尝试了很多东西,而且我为什么会遇到这样的情况。

附加信息:nginx访问日志显示200 / OK响应当访问块2 URL(https没有www),但响应是简单的空。

解决 – 这是由于魔法失败的情况。

域名注册商控制面板具有www / no-www便利设置,导致覆盖DNS设置的redirect。

禁用便利设置(即select“无偏好”)使得实际的DNS设置工作。