Question
Nginx fails to redirect '/' to '/index.php'
Nginx fails to call index.php file at ’/’ endpoint. In /etc/nginx/sites-available/default
, I have added location /
section to rewrite to ’/index.php’ (see below). However, when I enter my-site.com to the url bar, I get 403 Forbidden error ([error] 18041#18041: *2 directory index of “/var/www/html/” is forbidden).
When I enter my-site.com/index.php, it works correctly. Also, I’m able to see a page other than 403 Forbidden if I add an ‘index.html’ fie to my document directory, /var/www/html. Even with fastcgi_index index.php;
and removed 'index.html’, I don’t see the index.php file in ’/’ endpoint.
/etc/nginx/sites-available/default
server {
listen 80;
listen [::]:80;
server_name my-site.com www.my-site.com;
return 301 https://$server_name$request_url;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
include snippets/ssl-my-site.com.conf;
include snippets/ssl-params.conf;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name my-site.com www.my-site.com;
location ~ [^/].php(/|$) {
fastcgi_split_path_info ^(.+?.php)(/.*)$;
if (!-f /var/www/html$fastcgi_script_name) {
return 404;
}
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
fastcgi_pass unix:var/run/php/php7.0-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_read_timeout 300;
}
location ~ /.ht {
deny all;
}
location ~ /.well-known {
allow all;
}
location /phpmyadmin {
index index.php;
}
# Rewrite rules for WordPress Multi-site.
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
}
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×
UPDATED /etc/nginx/sites-available/default