Nginx server location configuration

user3052667 asked:

I want the domains, ,…,* 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 I get a 404 not found error.

My answer:

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;

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.