0

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.

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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