【问题标题】:nginx location alias: static files ignored?nginx位置别名:静态文件被忽略?
【发布时间】:2013-07-19 03:50:20
【问题描述】:

我试图让 zabbix-frontend 与 nginx 一起工作。 这是我的 nginx 配置文件:

server {

    listen 80;
    server_name localhost;
    root /var/www/test/htdocs;
    index index.php index.html index.htm;


    location /zabbix {

        alias                   /usr/share/zabbix;
        index                   index.php;
        error_page              403 404 502 503 504  /zabbix/index.php;

        location ~ \.php$ {
            if (!-f $request_filename) { return 404; }
            expires                 epoch;
            include                 /etc/nginx/fastcgi_params;
            fastcgi_index   index.php;
            fastcgi_pass    unix:/var/run/php5-fpm.sock;
        }

        location ~ \.(jpg|jpeg|gif|png|ico)$ {
            access_log      off;
            expires         33d;
        }

    }


    location / {
            try_files $uri $uri/ /index.php;
            include /etc/nginx/proxy_params;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_read_timeout 120;
            include /etc/nginx/fastcgi_params;
    }

    include /etc/nginx/security;
    include /etc/nginx/main_rules;

}

/zabbix 中的 php 脚本正在运行!但是没有提供像/usr/share/zabbix/css.css 这样的文件(404)。错误日志中是这样的:

2013/07/19 20:23:33 [error] 13583#0: *1 open() "/var/www/test/htdocs/zabbix/css.css" failed (2: No such file or directory), client: xxx, server: localhost, request: "GET /zabbix/css.css HTTP/1.1"

如我们所见,nginx 正在主根目录/var/www/test/htdocs/ 中查找文件,而不是在别名目录/usr/share/zabbix/ 中查找文件。

为什么会这样,我该如何解决?

【问题讨论】:

    标签: php nginx debian alias zabbix


    【解决方案1】:

    我会尝试将它们分开。 /zabbix 仅带有别名, ~ ^/zabbix/*.php$ 带有 fastcgi。两者都在 / 位置之外,都带有 root。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 1970-01-01
      • 2019-04-02
      • 2014-01-26
      相关资源
      最近更新 更多