首页 > 解决方案 > 每次添加第二个虚拟主机后,NGINX 重启都会失败

问题描述

我不知道我做错了什么。首先,我尝试在 NGINX 中添加 Vhost,使站点中的新文件可用,然后链接到启用站点。这确实有效。

然后我尝试直接在 nginx.conf 文件中创建虚拟主机。有同样的问题。它适用于一台主机,但如果我添加另一台主机并尝试 /etc/init.d/nginx启动它总是说:

See "systemctl status nginx.service" and "journalctl -xe" for details.
failed!

我该如何解决?这是我的 nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    server_names_hash_bucket_size 64;

    ##
    # 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 text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name_;
        location / {
            root /var/www/html/;
            index index.html index.htm index.nginx-debian.html;
            autoindex on;
        }
        location ~ \.php$ {
            root /var/www/html/;
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        }
    }
    server {
        listen 80;
        server_name website.de;
        location / {
            root /var/www/dev1/;
            index index.html index.htm;
            autoindex on;
        }
        location ~ \.php$ {
            root /var/www/dev1/;
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        }
    }

}

标签: nginxserverdebianvhosts

解决方案


推荐阅读