I am encountering a 403 Forbidden error when trying to access my PHP files via Nginx. My server is running on Ubuntu 24.04 with PHP 8.3 and Nginx 1.24.0.
The Nginx configuration file for my site is as follows:
server {
listen 80;
server_name alertik.io;
root /var/www/html/app;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
error_log /var/log/nginx/alertik.io_error.log;
access_log /var/log/nginx/alertik.io_access.log;
}
I have already checked the permissions of my document root, confirmed that the index.php
file exists, and verified that php8.3-fpm
is running. However, the issue persists. I am using a cloud VPS hosting environment.
Does anyone have any suggestions on how to resolve this issue? Thanks!
Additional Information:
I have a codebase that generates essential static files such as index.html
and various JavaScript files every minute using PHP scripts. These files have an expiration time and are automatically updated via cron jobs.
Given this setup, I’m wondering if I need to explicitly define the paths for these dynamically generated static files in the Nginx root
configuration block or any other related directive.
Is there a recommended approach for handling frequently updating static files in the Nginx configuration?