2

安装 Symfony2 后,我正在尝试访问此 URL:

http://test/symfony/web/app_dev.php/

但它不起作用,因为斜杠,我得到一个 404。

这些工作正常:

http://test/symfony/web/app_dev.php
http://test/symfony/web/app_dev.php?/

在 Apache 中,/app_dev.php/something 和 /app_dev.php?/something 是相同的。关于如何在 Nginx 中进行这项工作的任何想法?

我尝试添加重写,但没有运气:

    location / {
            try_files $uri $uri/ @rewrite index.html;
    }

    location @rewrite {
            rewrite ^/(.*\.php)/(.*)$ $1?/$2;
    }
4

2 回答 2

1

这就是我所拥有的,它工作正常:

    location / {
            # Remove app.php from url, if somebody added it (doesn't remove if asked for /app.php on the root)
            rewrite ^/app\.php/(.*) /$1 permanent;

            try_files $uri $uri/ /app.php?$query_string;
    }

    location ~ \.php$ {
            try_files $uri = 404;
            # Below is for fastcgi:
            # fastcgi_pass    127.0.0.1:9000;
            # fastcgi_index   app.php;
            # include         /etc/nginx/fastcgi_params;
            # fastcgi_param   SCRIPT_FILENAME /mnt/www/live/current/web$fastcgi_script_name;
            # fastcgi_param   SERVER_PORT 80;
            # fastcgi_param   HTTPS off;
    }
于 2012-05-21T19:04:21.257 回答
0

我终于偶然发现了一个对我有用的答案:

    location ~ /directory/(.*\.php)(/.*)$ {
            set $script_filename $1;
            set $path_info $2;
            fastcgi_param  PATH_INFO        $2;
            alias /place/directory/$1;
            include fastcgi_params;

https://github.com/plack/Plack/issues/281

这是文档中的相关片段:请注意,它们都没有使用 nginx 提供的 FCGI 参数作为 script_name 或 path_info ,因为已知它是不正确的。

location / {
 set $script "";
 set $path_info $uri;
 fastcgi_pass unix:/tmp/fastcgi.sock;
 fastcgi_param  SCRIPT_NAME      $script;
 fastcgi_param  PATH_INFO        $path_info;
于 2012-11-01T19:28:05.547 回答