By kerns
If I drop an index.html file into my web root it is recognized fine. An index.php file is, however, not served and a 403 forbidden is instead served. Unless you explicitly request it in the URI and then it will be served.
But then it is also served as the 404 apparently??? 🤯🤷🏻♂️…where any nonsense address or string that would otherwise serve a 404 is serving index.php just fine.
Go figure. As in please, …go help me figure this out. Such a strange matrix of behaviors.
I am using DO’s Nginx configurator, but to be fair have had the same or similar problems on many past Nginx setups. Why setting up sane defaults for index.html and index.php fallbacks is so tedious and invites so much different and often contradictory advice will remain a mystery to me. I’ve seen so many versions now of what a location try_files {} directive “should” look like, I am not sure what to believe.
Any help or hints appreciated.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello,
The following Nginx server block usually works well for me:
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
You first need to add the index.php file in the index list and then also have a ~ \.php$ location, so that Nginx would know how to handle the .php requests.
Hope that this helps! Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.