0

My current NGINX & PHP-FPM setup works when given a working filepath like example.com/index.php, but still serves the index.php as a download when visiting example.com without a file.

I've tried adding a location / redirect and try_files, but it still doesn't redirect properly.

I know how it's done using .htaccess files, but I'd like to do this in NGINX to avoid changing every repository.

Here's my current conf file.

server {
    server_name example.com;
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html;

    location / { 
        try_files $uri $uri/ =404;
    }   

    location ~ \.php$ {
        try_files $uri $uri/ =404;

        include fastcgi_params;
        fastcgi_pass php:9000;
        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }   
}

1 Answer 1

2

Remove try_files $uri $uri/ =404; from location ~ \.php$ {.

Sign up to request clarification or add additional context in comments.

1 Comment

Removing that and adding index index.php as a global parameter fixed it. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.