Nginx,LetsEncrypt - [emerg]" ssl_certificate"这里不允许使用/etc/nginx/sites-enabled/example.com.conf:33 nginx:

时间:2017-08-30 12:35:59

标签: ssl nginx lets-encrypt

我试图使用let encrypt为我的网站生成ssl证书,但收到以下错误:

[emerg]" ssl_certificate"这里不允许使用/etc/nginx/sites-enabled/example.com.conf:33 nginx:配置文件/etc/nginx/nginx.conf

我使用的是Virtualmin,Nginx

任何帮助都将受到高度赞赏

----------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -----------

site.com.conf

server {

    server_name example.com www.example.com;
    listen 10.0.1.4;
    root /home/example/public_html/public;
    index index.html index.php;
    access_log /var/log/virtualmin/example.com_access_log;
    error_log /var/log/virtualmin/example.com_error_log;
    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE nginx;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;
    fastcgi_param SCRIPT_FILENAME /home/example/public_html/public$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param DOCUMENT_ROOT /home/example/public_html/public;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param REMOTE_PORT $remote_port;
    fastcgi_param SERVER_ADDR $server_addr;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;
    fastcgi_param HTTPS $https;

    location / 
    {
        try_files $uri $uri/ /index.php?$query_string;
        gzip on;
    }

    location ~* \.(?:css|js|woff|eot|svg|ttf|otf|png|gif|jpe?g) 
    {
        expires max;
    }

    location ~ \.php$ 
    {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht 
    {
        deny all;
    }

    location ^~ /.well-known/acme-challenge/ {

        alias /home/example/public_html/;
    }

    listen 10.0.1.4:443 default_server ssl;
    ssl_certificate /home/example/ssl.cert;
    ssl_certificate_key /home/example/ssl.key;
}

Nginx Conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

     gzip_vary on;
     gzip_proxied any;
     gzip_comp_level 6;
     gzip_buffers 16 8k;
     gzip_http_version 1.1;
     gzip_types text/plain application/x-font-ttf text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    server_names_hash_bucket_size 128;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

grep -rHn" ssl_certificate"的结果的/ etc / nginx的

/etc/nginx/snippets/snakeoil.conf:4:ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
/etc/nginx/snippets/snakeoil.conf:5:ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
/etc/nginx/sites-available/example.com.conf.save:31:    ssl_certificate /home/example/ssl.cert;
/etc/nginx/sites-available/example.com.conf.save:32:    ssl_certificate_key /hom/example/ssl.key;
/etc/nginx/sites-available/example.com.conf:57: ssl_certificate /home/example/ssl.cert;
/etc/nginx/sites-available/example.com.conf:58: ssl_certificate_key /home/example/ssl.key;

2 个答案:

答案 0 :(得分:0)

您的问题是您在编辑器中编辑了一个创建备份.save文件

的文件

所以删除文件

rm /etc/nginx/sites-available/example.com.conf.save

同时更改

include /etc/nginx/sites-enabled/*;

include /etc/nginx/sites-enabled/*.conf;

以便下次不会发生此类问题

答案 1 :(得分:0)

如果这可以帮助其他人...

我得到的错误是类似的:

<块引用>

“ssl_certificate”指令在 /etc/nginx/sites-enabled/website:22 中是不允许的

事实证明我错误地将 ssl_certificatessl_certificate_key 条目插入大括号内,如下所示:

    server {
    listen 443 ssl;
    listen [::]:443 ssl;

    root /var/www/website/public;
    index index.php index.html index.htm;

    server_name pamsnetwork.com www.pamsnetwork.com;

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

    location ~ \.php$ {
        try_files $uri $uri/ /index.php?$query_string;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

    ssl_certificate    /etc/ssl/certificate.crt;

    ssl_certificate_key    /etc/ssl/private/private.key;
    }
}

什么时候应该是这样:

    server {
    listen 443 ssl;
    listen [::]:443 ssl;

    root /var/www/website/public;
    index index.php index.html index.htm;

    server_name pamsnetwork.com www.pamsnetwork.com;

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

    location ~ \.php$ {
        try_files $uri $uri/ /index.php?$query_string;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

    }

    ssl_certificate    /etc/ssl/certificate.crt;

    ssl_certificate_key    /etc/ssl/private/private.key;
}