NginX和Munin - 地址和404错误

3

我有一个运行nginx+php-fpm的服务器,配置非常简单:

server {
    listen   80;
    server_name ipoftheserver;
    access_log /var/www/default/logs/access.log;
    error_log /var/www/default/logs/error.log;

    location / {
        root   /var/www/default/public_html;
        index  index.html index.htm index.php;
    }


    location ^~ /munin/ {
        root /var/cache/munin/www/;
        index index.html index.htm index.php;
    }

    location ~\.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/default/public_html$fastcgi_script_name;
    }
}

但是当我打开ipoftheserver/munin/时,会收到404错误(当我请求ipoftheserver/时,在/var/www/default/public_html上的文件被正确侦听)。
Munin已安装并且运行正常。如果我删除这个配置,并使用另一个配置,则所有内容都正常工作(但不在/munin/目录中)。
server {
  server_name ipoftheserver;
  root /var/cache/munin/www/;
  location / {
    index index.html;
    access_log off;
  }
}

如何修复?非常感谢您的帮助。
1个回答

3

使用别名而不是根目录解决问题

server {
    listen   80;
    server_name ipoftheserver;
    access_log /var/www/default/logs/access.log;
    error_log /var/www/default/logs/error.log;

    location / {
        root   /var/www/default/public_html;
        index  index.html index.htm index.php;
    }


    location /munin/ {
        alias /var/cache/munin/www/;
        index index.html index.htm index.php;
    }

    location ~\.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME /var/www/default/public_html$fastcgi_script_name;
    }
}   

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接