【问题标题】:nginx fastcgi configuration for CGI::Application appCGI::Application 应用程序的 nginx fastcgi 配置
【发布时间】:2012-08-05 12:27:10
【问题描述】:

我正在尝试让 C::A 应用在 nginx fastcgi 环境(debian 6.0)中运行并使用 spawn-fcgi。

C::A 路由配置使用$self->mode_param( path_info=> 1, param => 'rm' );

问题是无论我请求什么 C::A 应用程序 url(example.com/citiesexample.com/profile/99 等),它总是显示主页,这就是 example.com/index.pl 所做的。

我的 nginx 设置是

server {
    listen   80;
    server_name example.com;
    root /var/www/example.com/htdocs;
    index  index.pl index.html;

    location / {
        try_files $uri $uri/ /index.pl;
    }

    location ~ .*\.pl$ {
            include fastcgi_params;   # this is the stock fastcgi_params file supplied in debian 6.0
            fastcgi_index index.pl;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PERL5LIB "/var/www/example.com/lib";
            fastcgi_param CGIAPP_CONFIG_FILE "/var/www/example.com/conf/my.conf";
            fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }

}

我已经以类似的方式成功设置了几个 php 应用程序。

然而,在这种情况下,我怀疑我没有将基本的fastcgi_param 传递给它所需要的 C::A。

你有什么想法?

【问题讨论】:

    标签: perl nginx cgi-application


    【解决方案1】:

    我维护 CGI::Application 并使用 Nginx。我没有做过同样的事情,但我会试试这个:

    fastcgi_split_path_info ^(/index.pl)(.*)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    

    这应该捕获并转发您需要的 PATH_INFO。

    参考资料:

    【讨论】:

    • 感谢您的回复。但我收到 500 个内部错误和一堆递归重定向,如“/index.pl/index.pl/cities”,为 nginx 错误日志打开了调试。
    • 感谢您尝试我最初的想法。我现在用一个完全不同的建议修改了这个问题。
    • 我认为这是在正确的轨道上。但是,由于某种原因,path_info 部分似乎没有从 nginx 传递到我的应用程序。我已手动将 path_info 设置为其他内容,但仍未看到它出现在 C::A 应用程序中。
    • 目前,我正在使用 request_uri 手动设置 path_info 作为解决方法...
    • 我认为问题在于 split_path_info 正则表达式可能是错误的,因为“/index.pl”不在请求 URI 中,那么它将是:fastcgi_split_path_info ^()(.*)$; ... 但是,我认为这相当于您将 $request_uri 作为 PATH_INFO 传递的想法。那么,您现在可以使用了吗?
    【解决方案2】:

    我最终在我的 C::A 应用程序中解决了这个问题。我在这里记录它。

    所以我没有设法让 nginx 将 PATH_INFO 传递给我的 C::A 应用程序。为了解决这个问题,我在我的 C::A 应用程序中将 PATH_INFO 的值设置为 REQUEST_URI,以便它选择正确的运行模式。

    另外,nginx 也没有通过QUERY_STRING,所以我不得不将$query_string 附加到catch all 路由,以便向下传递QUERY_STRING

    我的 nginx 配置最终是这样的:

    server {
        listen   80;
        server_name example.com;
        root /var/www/example.com/htdocs;
        index  index.pl index.html;
    
        location / {
            try_files $uri $uri/ /index.pl?$query_string;
        }
    
        location ~ .*\.pl$ {
                include fastcgi_params;   # this is the stock fastcgi_params file supplied in debian 6.0
                fastcgi_index index.pl;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PERL5LIB "/var/www/example.com/lib";
                fastcgi_param CGIAPP_CONFIG_FILE "/var/www/example.com/conf/my.conf";
                fastcgi_pass unix:/var/run/fcgiwrap.socket;
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-19
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      相关资源
      最近更新 更多