If the index file is not specified in Nginx settings, the server will return a 403 Forbidden error when accessing the root directory. To fix this problem, you need to add the index directive to the server configuration and specify the desired file (usually index.html or index.php).
The 403 Forbidden error in Linux means that the user who is accessing the server does not have access rights to the requested resource. This can be caused by incorrect permissions on a file or directory, server security settings, or Nginx configuration.
To fix this error, you need to make sure that file and directory permissions are set correctly and check the server configuration
Example:
server {
listen 80;
server_name example.com;
root /var/www/example.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
In this example, we have specified that when accessing the root directory, the server will look for the index.html file and display its contents. If such a file is missing, a 404 Not Found error will be returned.
After making changes to the server configuration, you must restart Nginx to apply the settings:
sudo systemctl restart nginx
If you request a URL like /vstats/
, but you don't have an index file specified in your Nginx settings, you will fail and get a 404. You can add an index directive to your location
:
location / {
index index.php index.html index.htm;
}
Or directly to server, in Nginx all locations inherit the directives set in server