Nginx 无法指向同一域上的 https 服务器块

Nginx 无法指向同一域上的 https 服务器块

我正在尝试使用 nginx 通过 https 提供静态文件。

设置

DNS 正确将子域名指向 AWS IP:

subdomain1.website.com -> correct IP

工作配置

我发现以下简单的服务器设置完全正常工作。但是,当我将其修改为转发到 https 时,它会失败且没有错误。

# /etc/nginx/sites-available/default
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    server_name subdomain1.website.com;

    root /usr/share/nginx/temp-content;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

尝试重定向到 https

# /etc/nginx/sites-available/default
server {
    listen 443 ssl;

    server_name subdomain1.website.com;

    root /home/deploy/temp-content;

    ssl_certificate /etc/letsencrypt/live/subdomain1.website.io/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/subdomain1.website.io/privkey.pem;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_stapling on;
    ssl_stapling_verify on;
    add_header Strict-Transport-Security max-age=15768000;

}

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    server_name subdomain1.website.com;
    return 301 https://$server$request_uri;
}

我完全不明白为什么会失败。Nginx 只返回 301,error.log没有相关日志。

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.4.6 (Ubuntu)</center>
</body>
</html>

编辑:只想包含所提供的文件的权限/usr/share/nginx/temp-content与中的(工作)文件的权限相同/usr/share/nginx/html

答案1

解决方案,正如 Drifter104 提到的,是安全组中的 443 端口被关闭了。不久前服务器上就发生过这种情况,然后安全组被更改了。

感谢您指出了这一点!

相关内容