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 want the domains example.com/a/1234/asdf, example.com/a/7890/qwer ,..., example.com/a/* to serve a webpage from the same index file, /var/www/foo/bar/index.php

My nginx is configed like this:

server {

        listen 80;
        root /var/www;
        index index.php;

        rewrite */a/(.*) /var/www/foo/bar/index.php;

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

When I goto example.com/a/1234/asdf I get a 404 not found error.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

You probably don't have a file /var/www/var/www/foo/bar/index.php. So of course it can't be found. Remember that these paths are relative to the document root.

You probably want something like:

rewrite */a/(.*) /foo/bar/index.php last;
share|improve this answer
    
OK I tried that fix and I'm still getting the error msg. Is there any way to debug this? –  user3052667 Nov 30 '13 at 18:42
    
You can turn on the rewrite_log. –  Michael Hampton Nov 30 '13 at 18:43
    
I see this error in error.log open() "example.com/a/1234/asdf" failed (2: No such file or directory)...so its not trying the rewrite at all. And I have restarted nginx. –  user3052667 Nov 30 '13 at 18:49
    
My current config: server { listen 80; root /var/www; index index.php; rewrite */a/(.*) /foo/bar/index.php last; location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } } –  user3052667 Nov 30 '13 at 18:50
    
I might have found the problem. '$sudo service nginx restart' is not actually restarting nginx. –  user3052667 Nov 30 '13 at 18:53
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.