Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to use the following line in my /etc/nginx/sites-enabled/mydomain.com configuration file.

rewrite ^/(\w+)$ ./index.php?filename=$1 last;

It keeps the URL short and lets me include something from index.php and it'll apply for every file.

It was working fine when I used apache and a .htaccess file, but when I switched it into nginx, it seems like php-fastcgi is not handling the request since it does not end with .php

I think I should adjust the following part which is in the same file.

    location ~ \.php$ {
            root /home/mydomain/public_html;
            fastcgi_pass localhost:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
    }

Any suggestions, or should I revert back to Apache?

And I also found out that when posting to a rewrited url, the variables are not received.. Seems to be lost during the rewrite process.

share|improve this question
    
Can you paste the contents of fastcgi_params? –  matzahboy Jul 27 '11 at 13:48
add comment

2 Answers

Removing the period, and add args to keep the query string variables in tact.

rewrite ^/(\w+)$ /index.php?filename=$1&$args last;
share|improve this answer
add comment

Your SCRIPT_FILENAME path is fine, so this means PHP does not have permission to read the PHP files. First find out which user/group your PHP processes run as (you can see this in your configuration file or by running ps aux | grep "php")

Next you want to check the permission of the files themselves, make sure that either the user or group that PHP runs under has the appropriate permissions. If those are fine then check the full directory path and make sure that the user or group has execute permission on the directory as a process needs execute permission to enter the directory.

Lastly, read the answer from h0tw1r3 and fix your rewrite as well. :)

Edit: Just noticed the period in your rewrite, and I think that's actually most likely it, so if the other answers fixes your issue you can ignore this one.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.