Hi there! A 403 Forbidden error on an Nginx server in CloudPanel usually means the server is denying access due to one of the following reasons:
🔹
1. No index file in the directoryBy default, Nginx looks for files like index.html or index.php. If none are found, it doesn’t know what to show and returns a 403 error.
Solution:Create a simple index.html file like this:
<!DOCTYPE html>
<html>
<head><title>Welcome</title></head>
<body><h1>Hello World!</h1></body>
</html>
Place it inside the directory you're trying to access.
🔹
2. autoindex is turned offIf there’s no index file and you want to list all files in the directory, you need to enable the autoindex setting.
How to do it:Open the config file:
sudo nano /etc/nginx/sites-available/default
Inside the location / block, add:
nginx
KopyalaDüzenle
location / {
autoindex on;
}
Then restart Nginx:
sudo systemctl restart nginx
⚠️
Warning: Enabling autoindex may expose directory contents to the public. Only use it when absolutely necessary.
🔹
3. Incorrect file or directory permissionsNginx might not have permission to access the folder.
Solution:sudo chown -R www-data:www-data /var/www/html/target_folder
sudo chmod -R 755 /var/www/html/target_folder
This ensures the Nginx process can read the files and directories.
✅
Extra Tips:- Disable autoindex after use.
- Set index index.html index.php; in your config.
- Avoid giving full permissions like 777 – it’s a security risk.
With these steps, you should be able to fix the “403 Forbidden” error on Nginx when using CloudPanel. Hope it helps! 😊