为什么Nginx 1.10.0失败了多个服务器块?

时间:2016-06-06 18:21:18

标签: ubuntu nginx

我在Ubuntu 16.04节点上设置nginx 1.10.0服务器时遇到了很大问题。
具有配置的第一个Virtualhost

server {
   server_name lukvonstrom.de;

   server_tokens off;

   listen 80;
   listen [::]:80;

   return 301 https://lukvonstrom.de$request_uri;

}




server {

    server_name lukvonstrom.de;

    server_tokens off;

    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    root /var/www/lukvonstrom.de/;

    index index.html;

    add_header X-Frame-Options SAMEORIGIN;
    add_header X-Content-Type-Options nosniff;
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;

    ssl_certificate /etc/letsencrypt/live/lukvonstrom.de/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/lukvonstrom.de/privkey.pem;

    ssl_session_cache shared:SSL:50m;
    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES$

    resolver 8.8.8.8;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /etc/letsencrypt/live/lukvonstrom.de/fullchain.pem;

    ssl_dhparam /etc/nginx/ssl/dhparam4096.pem;

}

正在运行,没有任何问题。当我在conf.d目录中添加一个新的主机时,这个例子是git.lukvonstrom.de,配置如下:

server {
    server_name git.lukvonstrom.de;

    server_tokens off;

    listen 80;
    listen [::]:80;

    return 301 https://git.lukvonstrom.de$request_uri;
}

server {
    server_name git.lukvonstrom.de;
    client_max_body_size 50m;

    location / {
            proxy_pass http://localhost:3000;
    }

    server_tokens off;

    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    add_header X-Frame-Options SAMEORIGIN;
    add_header X-Content-Type-Options nosniff;
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;

    ssl_certificate /etc/letsencrypt/live/git.lukvonstrom.de/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/git.lukvonstrom.de/privkey.pem;
    ssl_session_cache shared:SSL:50m;
    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES$
    resolver 8.8.8.8;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /etc/letsencrypt/live/git.lukvonstrom.de/fullchain.pem;
    ssl_dhparam /etc/nginx/ssl/dhparam4096.pem;
}
}

nginx -t产生以下输出

nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/conf.d/git.lukvonstrom.de.conf:44
nginx: configuration file /etc/nginx/nginx.conf test failed

有没有人可以解释为什么这个错误发生了?

提前致谢, LukvonStrom

1 个答案:

答案 0 :(得分:0)

您可以尝试使用不同的服务器名称吗?对于不同的服务器块,服务器名称“lukvonstrom.de”应该是唯一的。