0

I have nginx setup with an alias and am trying to do a rewrite rule with try_files. The problem is that it's preprending the document root and not finding the file. Configuration:

server {
    listen      80;
    server_name mysite.com;
    root        /var/www/default;
    index       index.html index.htm index.php;

    location /coolapp {
        alias /home/myhome/coolapp/www/;
        index     index.php;
        try_files $uri $uri/ /home/myhome/coolapp/www/index.php?url=$uri&$args;

        location ~ \.php$ {
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include       /etc/nginx/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
        }
    }
}

And in the nginx error log:

[error] 21903#0: *2 open() "/var/www/default/home/myhome/coolapp/www/index.php" failed (2: No such file or directory) ...

Why is it prepending the root in try_files? I want the alias treated as its own root. What am I doing wrong here?

Wells Oliver
  • 221
  • 6
  • 11

1 Answers1

1

You used alias where you should have used another root.

root adds the specified path to the request.
alias replaces the location path specified path-part.

You're also running into a bug, but you won't once you put the proper configuration in place.

84104
  • 12,905
  • 6
  • 45
  • 76