1

I installed a php script in /files/ subfolder on Nginx but when I access the page, it's not working. Just showing 404 not found.

I added this in the config but not working.

location ^~ /files {

 if (!-e $request_filename) { rewrite ^/(.*) /files/index.php?_page_url=$1 last; }

location ~ \.php$ {
if (!-e $request_filename) { rewrite ^/(.*) /files/index.php?_page_url=$1 last; }
 fastcgi_pass unix:/run/php/php8.0-fpm-example.com.sock;
 index index.php;
 include /etc/nginx/fastcgi_params;
 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
 fastcgi_param PATH_INFO $fastcgi_path_info;
 fastcgi_param SCRIPT_FILENAME $request_filename;
 }
location /files/files/ {
 internal;
 }

 # these locations would be hidden by .htaccess normally
 location /files/logs/ {
 deny all;
 }
}

Here is my full nginx config, Thanks:

#=========================================================================#
# Default Web Domain Template #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
# https://docs.hestiacp.com/admin_docs/web.html#how-do-web-templates-work #
#=========================================================================#

server
{
 listen myip:443 ssl http2;
 server_name example.com;
 root /home/smart/web/example.com/public_html;
 index index.php index.html index.htm;
 access_log /var/log/nginx/domains/example.com.log combined;
 access_log /var/log/nginx/domains/example.com.bytes bytes;
 error_log /var/log/nginx/domains/example.com.error.log error;
 client_max_body_size 5G;

 ssl_certificate /home/smart/conf/web/example.com/ssl/example.com.pem;
 ssl_certificate_key /home/smart/conf/web/example.com/ssl/example.com.key;
 ssl_stapling on;
 ssl_stapling_verify on;

 include /home/smart/conf/web/example.com/nginx.hsts.conf*;

location /
 {

 location ~* ^.+\.(jpeg|jpg|png|webp|gif|bmp|ico|svg|css|js)$
 {
 expires max;
 fastcgi_hide_header "Set-Cookie";
 }

 location ~ [^/]\.php(/|$)
 {
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 if (!-f $document_root$fastcgi_script_name)
 {
 return 404;
 }

 fastcgi_pass unix:/run/php/php8.0-fpm-example.com.sock;
 fastcgi_index index.php;
 include /etc/nginx/fastcgi_params;
 include /home/smart/conf/web/example.com/nginx.fastcgi_cache.conf*;
 }

 }

location ^~ /files {

 if (!-e $request_filename) { rewrite ^/(.*) /files/index.php?_page_url=$1 last; }

location ~ \.php$ {
if (!-e $request_filename) { rewrite ^/(.*) /files/index.php?_page_url=$1 last; }
 fastcgi_pass unix:/run/php/php8.0-fpm-example.com.sock;
 index
index.php;
 include /etc/nginx/fastcgi_params;
 fastcgi_split_path_info ^(.+?\.php)(/.*)$;
 fastcgi_param PATH_INFO $fastcgi_path_info;
 fastcgi_param SCRIPT_FILENAME $request_filename;
 }
location /files/files/ {
 internal;
 }

 # these locations would be hidden by .htaccess normally
 location /files/logs/ {
 deny all;
 }
}


 location /error/
 {
 alias /home/smart/web/example.com/document_errors/;
 }

 location ~ /\.(?!well-known\/)
 {
 deny all;
 return 404;
 }

 location /vstats/
 {
 alias /home/smart/web/example.com/stats/;
 include /home/smart/web/example.com/stats/auth.conf*;
 }


 include /etc/nginx/conf.d/phpmyadmin.inc*;
 include /etc/nginx/conf.d/phppgadmin.inc*;
 include /home/smart/conf/web/example.com/nginx.conf_*;
}
2
  • I am missing log files?
    – djdomi
    Aug 24, 2022 at 17:11
  • What is the exact URL you are accessing and what is the response? Aug 24, 2022 at 20:27

0

You must log in to answer this question.

Browse other questions tagged .