Nginx www和ssl传递的非www被忽略

时间:2019-01-18 22:12:47

标签: nginx

我的nginx conf在一个IP地址上具有ssl和多个域证书文件不同:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name otherdomain.network;
    ssl_certificate /certificates/fullchain.pem;
    ssl_certificate_key /certificates/privkey.pem;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://otherdomain:7001/;
        proxy_redirect off;
# Socket.IO Support
        proxy_http_version 1.1;
    }
}

server {
    listen 443 ssl;
    server_name domain.xyz;
    ssl_certificate /certificates/decentreit.xyz/fullchain.pem;
    ssl_certificate_key /certificates/decentreit.xyz/privkey.pem;
    return 301 https://www.domain.xyz;
}

server {
    listen 443 ssl;
    server_name *.domain.xyz;
    ssl_certificate /certificates/domain.xyz/fullchain.pem;
    ssl_certificate_key /certificates/domain.xyz/privkey.pem;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://domain.xyz:8000/;
        proxy_redirect off;
# Socket.IO Support
        proxy_http_version 1.1;
    }
}

如果我在浏览器中用www或不带www的普通网址写的都很好,但是没有https前缀:

  1. www.domain.xyz 2.domain.xyz

如果网址为“ https://domain.xyz

ssl握手失败

ps Stackoverflow拒绝了我的“唯一代码”,但问题似乎已经完成,因此请在下面添加一些文字

0 个答案:

没有答案