configurationSSL后无法访问Nginx Web服务器

我有一个开发版本的Django网站,域名为“mysite.com”,我曾经通过URL“ http://web01.mysite.com ”访问我的网站。 我刚刚安装了通配符数字证书,现在我无法访问该网站。 如果我使用“ https://web01.mysite.com ”或“ http://web01.mysite.com ”,我会得到一个快速的“ERR_CONNECTION_REFUSED”消息。 我已经阅读了Nginx的SSL文档,在Nginx上设置了许多关于SSL的博客文章,并且研究了这个错误,但我无法弄清楚什么是错的。

我的服务器是Debian 8.7。 我正在运行Nginx 1.6.2,“–with-http_ssl_module”是configuration参数之一。 我也使用默认的nginx.conf文件。 nginx进程在默认帐户“www-data”下运行。

我的证书和私钥文件位于以下目录中:

drwr-xr-x root root /srv/ssl/mysite.com/ 

这里是我的捆绑证书和私钥文件驻留在上述目录中:

 -r--r----- root www-data ssl-bundle.crt -r--r----- root www-data mysite.com.key 

当我configuration通配符证书时,我指定“* .mysite.com”作为通用名称。

这是我的/etc/nginx/sites-enabled/mysite.conf文件:

 server_tokens off; upstream gunicorn { server 127.0.0.1:8000 fail_timeout=0; } server { #listen 80; listen 443 ssl; server_name web01.mysite.com; ssl_certificate /srv/ssl/mysite.com/ssl-bundle.crt; ssl_certificate_key /srv/ssl/mysite.com/mysite.com.key; location / { root /srv/http/mysite.com/repo; # Redirect all HTTP requests to HTTPS rewrite ^ https://$server_name$request_uri permanent; } access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; client_max_body_size 4G; keepalive_timeout 5; # Pass static file requests to the file server location /static/ { proxy_pass http://45.33.33.53; } location /media/ { alias /var/www/mysite.com/media/; } try_files $uri @django; location @django { proxy_pass http://gunicorn; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; # Capture originating IP address of client # This allows me to view the HTTP_X_FORWARDED_FOR field in request.META # in my login_firewall view. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 

我在我的防火墙上打开了端口443:

 Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere REJECT all -- loopback/8 anywhere reject-with icmp-port-unreachable ACCEPT icmp -- anywhere anywhere state NEW icmp echo-request ACCEPT tcp -- anywhere anywhere tcp dpt:ssh state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:http state NEW ACCEPT tcp -- anywhere anywhere tcp dpt:https state NEW ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED LOG all -- anywhere anywhere limit: avg 5/min burst 5 LOG level debug prefix "iptables_INPUT_denied: " REJECT all -- anywhere anywhere reject-with icmp-port-unreachable Chain FORWARD (policy ACCEPT) target prot opt source destination LOG all -- anywhere anywhere limit: avg 5/min burst 5 LOG level debug prefix "iptables_FORWARD_denied: " REJECT all -- anywhere anywhere reject-with icmp-port-unreachable Chain OUTPUT (policy ACCEPT) target prot opt source destination 

如果我做“sudo netstat -plnt | grep nginx”,我可以看到Nginx正在侦听端口443:

 tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 25537/nginx -g daem 

我已经检查了nginx错误日志(debugging开启),它是空的。 我更改后重新加载了nginxconfiguration文件。

ssl.conf是否需要从nginx.conf或我的mysite.conf文件中包含? 这个答案提到,作为一个要求,但我没有看到在Nginx文档讨论,也没有看到我在网上阅读的任何configuration文章。

有没有人看到我在做什么错了?

它看起来像你从httpsredirect到https导致redirect循环。 我不知道为什么你会得到一个连接被拒绝的消息,但上面的评论证实了这一点。

你的第二个问题,403禁止,可能是一个权限问题。 用户Nginx是否正在运行(nginx.conf中的用户指令)是否具有相应位置块引用的资源的权限?