【问题标题】:Nginx multiple domains doesn't workNginx 多个域不起作用
【发布时间】:2014-10-13 00:25:46
【问题描述】:

我有一个完美的配置,即 nginx、php5-fpm、apc、varnish 和 mariadb。一切都完美无缺,除了;

我正在托管一个网站,因为我的服务器资源很高且可用,我想在同一台服务器上托管其他网站。当我尝试将不同的网站添加到 nginx 中时,服务根本不会重新启动。

这是我在一切正常时的配置文件:

    server {
    listen  8080; 

    root /usr/share/nginx/www;
    index index.php index.html index.htm;

    server_name www.domain1.com;

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

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        allow ::1;
        deny all;
    }


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

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

我不想为不同的虚拟主机使用单独的文件,我想在默认文件中做所有事情。但是当我像下面添加另一个虚拟主机并保存默认文件时。 nginx 不会重启。

 server {
    listen  8080; 

    root /usr/share/nginx/www;
    index index.php index.html index.htm;

    server_name www.domain1.com;

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

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        allow ::1;
        deny all;
    }


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

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

server {
    listen  8080; 

    root /usr/share/nginx/domain2;
    index index.php index.html index.htm;

    server_name www.domain2.com;

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

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        allow ::1;
        deny all;
    }


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

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

请帮我解决这个问题。我认为有些冲突,但不知道是什么。

【问题讨论】:

    标签: nginx virtualhost


    【解决方案1】:

    好的,我只是通过调查错误日志找到了解决方案。

    2014/08/19 21:55:07 [emerg] 5927#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32
    

    错误日志告诉我增加哈希桶大小..

    我编辑了 nginx.conf 并按照错误日志中的建议将存储桶大小设置为 32,起初它不起作用,但后来我将它设置为 64 并且它起作用了。

    只需在 nginx.conf 中搜索“bucket”,取消注释,然后设置为 64(在某些情况下或更高)它就可以工作,除非还有其他问题。

    【讨论】:

    • 这就是错误日志的用途;-)。为了帮助您,我会问的第一个问题是:错误日志中有什么。
    猜你喜欢
    • 2021-05-10
    • 2017-09-29
    • 2017-11-21
    • 1970-01-01
    • 2020-07-18
    • 2012-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多