Nginx 目录别名错误地传递给 fcgi

Nginx 目录别名错误地传递给 fcgi

我有一个网站虚拟主机 example.com,它由 /home/erealms/www 静态提供。

但是,该网站运行一系列 perl 脚本,这些脚本位于不同的目录中。因此,我试图实现以下目标:

http://example.com/               -> /home/erealms/www
http://example.com/erealms        -> /home/erealms/ethereal/main
http://example.com/erealms/admin  -> /home/erealms/ethereal/mgmt/admin
http://example.com/erealms/config -> /home/erealms/ethereal/mgmt/config

除了以下目录之外的所有目录http://example.com/将会有 perl 文件 .pl 通过 fcgiwrapper 提供。

以下是我的当前配置:

server {
    add_header Cache-Control public;
    access_log /var/log/nginx/access.log main buffer=32k;
    error_log /var/log/nginx/error.log error;
    expires max;
    limit_req zone=gulag burst=200 nodelay;
    listen 80;
    server_name example.com;
    index index.html index.htm default.html default.htm;
    root /home/erealms/www;

    location ~* (\.jpg|\.png|\.css)$ {
        if ($http_referer !~ ^(http://rpn.ishikawa.sne.jp) ) {
            return 405;
        }
    }
    location = /favicon.ico {
        return 204;
    }
    location /erealms/config {
        root /home/erealms/ethereal/mgmt/config/;
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:8000;
        fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/mgmt/config$fastcgi_script_name;
    }
    location /erealms/admin {
        root /home/erealms/ethereal/mgmt/admin/;
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:8000;
        fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/mgmt/admin$fastcgi_script_name;
    }
    location /erealms {
        alias /home/erealms/ethereal/main;
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:8000;
        fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/main$fastcgi_script_name;
    }
}

您会注意到我同时使用了 root 和 alias 指令,因为我试图弄清楚到底发生了什么。但奇怪的是,我在下面列出了请求的目录以及 nginx 告诉 fcgiwrapper 访问这些目录的位置:

http://example.com/erealms        -> /home/erealms/ethereal/main/erealms
http://example.com/erealms/admin  -> /home/erealms/ethereal/mgmt/admin/erealms/admin
http://example.com/erealms/config -> /home/erealms/ethereal/mgmt/config/erealms/config

现在,为了让这个该死的东西能够进行进一步的测试,我刚刚创建了惰性符号链接,指向它们应该在的位置,但显然这不是一个非常优雅的解决方案。如果有人能指出正确的方向来修复当前设置,或者如果你对这个配置有一个更优雅的解决方案,我将不胜感激。

答案1

不确定在 SF 上如何回答你自己的问题,但这是我最终做的事情:

server {
    add_header      Cache-Control public;
    access_log      /var/log/nginx/access.log main buffer=32k;
    error_log       /var/log/nginx/error.log error;
    expires         max;
    limit_req       zone=gulag burst=200 nodelay;
    listen          80;
    server_name     rpn.ishikawa.sne.jp;
    root            /home/erealms/www;
    index           index.html;
    location ~* (\.jpg|\.png|\.css)$ {
            if ($http_referer !~ ^(http://rpn.ishikawa.sne.jp) ) {
                    return 405;
            }
    }
    location = /favicon.ico {
            return 204;
    }
    location ~ /erealms/config(/.*\.pl)$ {
            alias   /home/erealms/ethereal/mgmt/config;
            gzip off;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/tmp/cgi.sock;
            fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/mgmt/config/$1;
    }
    location ~ /erealms/admin(/.*\.pl)$ {
            alias   /home/erealms/ethereal/mgmt/admin;
            gzip off;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/tmp/cgi.sock;
            fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/mgmt/admin/$1;
    }
    location ~ /erealms(/.*\.pl)$ {
            alias   /home/erealms/ethereal/main;
            gzip off;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/tmp/cgi.sock;
            fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/main/$1;
    }
}

现在不幸的是,这导致了一些其他错误,我最终将仅使用 apache 后端来通过 nginx 前端提供动态内容,但我想我会把它留在这里以防其他人遇到类似的问题。

相关内容