SH10151
SH10151

Reputation: 974

Laravel on Nginx default / URI not working - requires "index.php" - Nginx config issue?

I've added a location block to serve a Laravel app from a sub URI (only) at /todos/

location /todos {
    try_files $uri $uri/ /todos/$query_string;
    index  index.php index.html index.htm;
    root /index.php;
    location ~ \.php$ {
        fastcgi_index index.php;
        fastcgi_read_timeout 300;
        fastcgi_pass   unix:/opt/bitnami/php/var/run/www.sock;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME /opt/bitnami/nginx/html/todos/public/index.php;
        fastcgi_param QUERY_STRING $query_string;
        include        fastcgi_params;
    }
}

But going to /todos/ URI doesn't work (serves up 403 Forbidden), it requires me to actually put in "index.php" - so Laravel only works with /todos/index.php.

What am I doing wrong?

UPDATE: Working config:

location /todos {
    try_files $uri $uri/ /todos/index.php?$query_string;
    index  index.php index.html index.htm;
    root /opt/bitnami/nginx/html/todos/public/;
    location ~ \.php$ {
        fastcgi_index index.php;
        fastcgi_read_timeout 300;
        fastcgi_pass   unix:/opt/bitnami/php/var/run/www.sock;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME /opt/bitnami/nginx/html/todos/public/index.php;
        fastcgi_param QUERY_STRING $query_string;
        include        fastcgi_params;
    }
}

Upvotes: 0

Views: 1036

Answers (1)

Walter Schweitzer
Walter Schweitzer

Reputation: 424

Your root needs to be:

root $directory_of_your_index.php_file;

And in Location add:

try_files $uri $uri/ /index.php?$query_string;

Upvotes: 1

Related Questions