没有为“listen ... ssl”指令定义“ssl_certificate”

Ahs*_*sim 19 ssl nginx lets-encrypt

我正在尝试为我的网站配置 nginx 服务器。我正在使用以下代码来配置我的服务器。如果我为 www.fastenglishacademy.fr (443) 服务器块添加 default_server ,它会起作用。

但在这种情况下,我所有的子域也会带来 www.fastenglishacademy.fr 的内容

如果我删除 default_server,我会收到以下错误:

nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/sites-enabled/fastenglishacademy.fr.conf:14
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)

我的 nginx 配置代码:

server {
        listen 80;
        listen [::]:80;
        server_name fastenglishacademy.fr;
        return 301 https://www.fastenglishacademy.fr$request_uri;
}
server {
        listen 80;
        listen [::]:80;
        server_name www.fastenglishacademy.fr;
        return 301 https://www.fastenglishacademy.fr$request_uri;
}

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name fastenglishacademy.fr;
        return 301 https://www.fastenglishacademy.fr$request_uri;
}

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        root /media/fea/www/fastenglishacademy.com;
        index index.html index.htm index.nginx-debian.html;
        server_name www.fastenglishacademy.fr;
        location / {
            etag on;
            try_files $uri$args $uri$args/ /index.html;
        }

        location ~* \.(jpg|jpeg|png|gif|ico|ttf|woff2|woff|svg)$ {
                expires 365d;
        }
        location ~* \.(css|js)$ {
                expires 30d;
        }

        location ~*  \.(pdf)$ {
                expires 15d;
        }
        #WARNING: Please read before adding the lines below!
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
        add_header X-Frame-Options DENY;
        add_header X-Content-Type-Options nosniff;

        # SSL Certificates
        ssl_certificate /path/to/fullchain.pem;
        ssl_certificate_key /path/to/privkey.pem;
        ssl_trusted_certificate /path/to/chain.pem;
}
Run Code Online (Sandbox Code Playgroud)

我的链接:

https://www.fastenglishacademy.fr/

https://api.fastenglishacademy.fr/

Tia*_*vêa 12

您的server部分缺失ssl_certificatessl_certificate_key声明。

您需要有一个.crt和一个.key文件才能使用 ssl 运行。

它应该看起来像

server {

  listen 80;

  listen 443 default_server ssl;
  ssl_certificate /etc/nginx/certs/default.crt;
  ssl_certificate_key /etc/nginx/certs/default.key;

  ... other declarations

}
Run Code Online (Sandbox Code Playgroud)