How to Fix the NGINX 403 Forbidden Error
Understanding the NGINX 403 Forbidden Error
The NGINX 403 Forbidden error happens when the server knows what the client wants but won't do it because it doesn't have the right permissions. This status code is sent back to the user to let them know that they don't have the right permissions to access the item they asked for. To keep a strong online profile and a high ranking on search engines, it is important to fix this error as soon as possible.
Server-Side Causes and Solutions
Cause 1: The Index File Wasn't Set Up Right
The index files are often set up wrong, which can lead to the NGINX 403 Forbidden error. NGINX will return a 403 error if the desired file is not in any of the directories that have been set up. How to fix it:
location / { index index.html index.htm index.php; }
Make sure that the index files you listed are in the right folders. If not, you'll need to add the missing index file or change the settings.
location / { autoindex on; autoindex_exact_size on; }
Cause 2: Incorrect Permissions on Files and Directories
The NGINX 403 Forbidden error can also be caused by files and folders with wrong permissions. In order to fix this:
# Find out who is in charge of the NGINX process (usually 'www-data'): ps auxf | grep nginx # Make sure the NGINX process user has the ability to read, write, and execute (RWX) on the entire path: sudo chown -R www-data:www-data /var/www/yourdomain.com # Make sure groups and files have the right permissions: sudo find /var/www/yourdomain.com -type d -exec chmod 755 {} \; sudo find /var/www/yourdomain.com -type f -exec chmod 644 {} \;
Client-Side Causes and Solutions
The 403 error can sometimes be caused by something on the client side. Here are some ways to deal with these situations:
- Ensure Correct Web Location: Check that you are going to the right web address. Check for any typos or URLs that don't work.
- Clear Your Browser's Cache: Clearing your browser's cache can fix problems with cookies that could cause the 403 error.
- Firewall or Proxy Settings: Make sure that your firewall or proxy settings do not block access to the website you are trying to reach.
Conclusion
To sum up, Codeyo Genie's skilled Support Engineers showed us how to fix the Digitalocean 403 forbidden nginx problem.