John Davidson

NGINX only executing "index.php" but not any other "*.php" files

0 comments
Message:


I'm trying to setup a CMS to run it's installation. The installation files are a setup folder and a file called "setup.php". If I access my website at "example.com/setup.php" it tries to download the file, but if I rename "setup.php" to "index.php" and navigate to "example.com/index.php" or just "example.com" it executes the php file.


My nginx config for the site is this:


server {
root /var/www/example.com;
index index.php index.html index.htm;
server_name example.com;

listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

location / { try_files $uri $uri/ /index.php?$query_string; }

# Pass the PHP scripts to FastCGI server
location ~ ^/index.php {
# Write your FPM configuration here
include snippets/fastcgi-php.conf;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
#fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#include fastcgi_params;
}

# Whitelist
## Let TastyIgniter handle if static file does not exists
location ~ ^/favicon\.ico { try_files $uri /index.php; }
location ~ ^/sitemap\.xml { try_files $uri /index.php; }
location ~ ^/robots\.txt { try_files $uri /index.php; }
location ~ ^/humans\.txt { try_files $uri /index.php; }

## Let nginx return 404 if static file does not exists
location ~ ^/assets/media { try_files $uri 404; }
location ~ ^/storage/temp/public { try_files $uri 404; }

location ~ ^/app/.*/assets { try_files $uri 404; }
location ~ ^/app/.*/actions/.*/assets { try_files $uri 404; }
location ~ ^/app/.*/dashboardwidgets/.*/assets { try_files $uri 404; }
location ~ ^/app/.*/formwidgets/.*/assets { try_files $uri 404; }
location ~ ^/app/.*/widgets/.*/assets { try_files $uri 404; }

location ~ ^/extensions/.*/.*/assets { try_files $uri 404; }
location ~ ^/extensions/.*/.*/actions/.*/assets { try_files $uri 404; }
location ~ ^/extensions/.*/.*/dashboardwidgets/.*/assets { try_files $uri 404; }
location ~ ^/extensions/.*/.*/formwidgets/.*/assets { try_files $uri 404; }
location ~ ^/extensions/.*/.*/widgets/.*/assets { try_files $uri 404; }

location ~ ^/themes/.*/assets { try_files $uri 404; }

}


server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

listen 80;
listen [::]:80;
server_name example.com;
return 404; # managed by Certbot


}

I changed the web address in the config before posting for security reasons. I'm extremely confused as to why this isn't working as if index.php executes, all .php files should. Any help in figuring this out would be appreciated.



My Answer:
the first location block that matches the request URI.

Rate this post

3 of 5 based on 4175 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us