启用S​​SL后,Nginx不会加载其他站点

时间:2016-04-15 18:27:16

标签: ssl nginx

这是我的/etc/sites-available/default

server {
    listen    443 default_server;
    server_name _;

    ssl on;
    ssl_certificate /etc/ssl/certs/example/example.com.crt;
    ssl_certificate_key /etc/ssl/certs/example/example.com.key;

    root /usr/share/nginx/html;
    index index.html index.htm;

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

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    return 301 https://$host$request_uri;

    root /usr/share/nginx/html;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

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

第一块是我最近添加的。我在这台服务器上托管了多个子域。这是sites-available/my.example.com

的示例
server {
    server_name my.example.com;

    access_log /var/data/log/nginx/my.example.com.log;
    error_log  /var/data/log/nginx/my.example.com.log;

    root       /var/data/www/lmy.example.com/htdocs;
    index      index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
}

每当我去http://my.example.com时,网站都会正常加载。但现在,转到https://my.example.com只会转到默认页面。 my.example.com文件是sites-enabled的符号链接。配置似乎很好,因为如果我对return 301 ...块中的行port 80发表评论,http://my.example.com会再次生效,但https://my.example.com会显示默认的nginx页面。

0 个答案:

没有答案