HappyDeveloper
HappyDeveloper

Reputation: 12805

Slash arguments in Nginx, PHP

I'm trying to access this URL, after installing Symfony2:

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

But it won't work, because of the trailing slash, I get a 404.

These ones work fine:

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

In Apache, /app_dev.php/something and /app_dev.php?/something were the same. Any idea on how to make this work in Nginx?

I tried adding a rewrite, with no luck:

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

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

Upvotes: 2

Views: 5188

Answers (2)

Michael J. Evans
Michael J. Evans

Reputation: 781

I finally stumbled across an answer that works for me:

    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

Here's the relevant snippet from the docs: note that none of them uses nginx-provided FCGI params for script_name or path_info since it's known to be incorrect.

location / {
 set $script "";
 set $path_info $uri;
 fastcgi_pass unix:/tmp/fastcgi.sock;
 fastcgi_param  SCRIPT_NAME      $script;
 fastcgi_param  PATH_INFO        $path_info;

Upvotes: 0

Anton Babenko
Anton Babenko

Reputation: 6636

This is what I have and it works fine:

    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;
    }

Upvotes: 1

Related Questions