添加 Lets Encrypt 后,Nginx 重定向到默认页面

添加 Lets Encrypt 后,Nginx 重定向到默认页面

一切正常,直到我安装 Let's encrypt 并修改 /etc/nginx/sites-available/default

我犯了什么错误

server {
        listen 80 default_server;
        listen [::]:80 default_server;



        root /var/www/html;


        index index.php index.html index.htm index.nginx-debian.html;
    server_name geekdashboard.com www.geekdashboaard.com;
    return 301 https://$server_name$request_uri;
}

server {

    # SSL configuration

    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    include snippets/ssl-geekdashboard.com.conf;
    include snippets/ssl-params.conf;

    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/ /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;
}

}

答案1

您的server块没有root指令来告诉 nginx 您的网站文件位于何处。因此,它从默认位置提供文件,这些文件是 nginx 附带的示例文件。

为了解决这个问题,请rootserver块中添加适当的指令。

答案2

从上面的代码片段来看,您的根目录root /var/www/html;指向默认的 nginx 页面。如果您已经更改了它,但它仍然存在,请在下面声明另一个根目录;


listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; include snippets/ssl-geekdashboard.com.conf; include snippets/ssl-params.conf;

具有


listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; include snippets/ssl-geekdashboard.com.conf; include snippets/ssl-params.conf; #new path root /path/to/your/project

相关内容