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

时间:2019-06-19 13:03: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

我的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;
}

我的链接:

https://www.fastenglishacademy.fr/

https://api.fastenglishacademy.fr/

2 个答案:

答案 0 :(得分:8)

您的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

}

答案 1 :(得分:0)

有同样的问题。 添加指令

import random

door = ['a', 'b', 'c', 'd']
nc = 0 # When not changed
c = 0  # When changed

tr = 100 #Total number of iterations
for a in range(tr):
    car = random.randint(0, 3) #Inquiry number with car behind

    pc = random.randint(0, 3) #Inquiry number chosen by the participant

    ed = [] #Empty door

for i in range(4):
    if i != pc and i != car:
        ed.append(door[i])


com = random.sample(ed, 2)

if pc == car:
    nc += 1


def list_remover(the_list, val):
    while val in the_list:
        the_list.remove(val)

list_remover(ed, com)


if not ed:
    c += 1

print((nc / tr) * 100, "%")
print((c / tr) * 100, "%")

解决了我的问题。