How to fix Digitalocean 403 forbidden nginx error?
When a client attempts to access a part of the webserver with insufficient permissions, the Nginx 403 Forbidden error is generated and displayed to the user.
Let’s take a look at the ways our Technical Support team took to fix it:
- Check to see if nginx is up and running.
systemctl status nginx
You must see something like this if nginx is up and running:
nginx.service - The nginx HTTP Server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-11-19 09:37:46 UTC; 2 days ago
Docs: https://httpd.nginx.org/docs/2.4/
If nginx is not running, the output will be as follows:
nginx.service - The nginx HTTP Server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: inactive (dead) since Fri 2019-11-22 08:41:01 UTC; 39s ago Docs: https://httpd.nginx.org/docs/2.4/
- If nginx isn’t already running, you can start it by typing:
systemctl start nginx
Then double-check the status to ensure that nginx is still running.
- If nginx failed to start after a reboot, you can allow it so that it starts the next time you reboot:
systemctl enable nginx
Check your nginx config syntax:
nginx -t
If you receive an error, you must first resolve the issue before restarting nginx:
systemctl restart nginx
- If you get Syntax OK when running nginx -t, your configuration is accurate, so verify your error logs:
tail -f /var/log/nginx/error.log
- Examine the file and folder permissions in your document root:
Consider the user which your nginx service is running as:
ps auxf | grep nginx
If you’re using Ubuntu, the user you must be www-data, so ensure that your files and folders are purchased by that user so that nginx can read and write to them:
chown -R www-data:www-data /var/www/yourdomain.com
- Then look to see if nginx is using the default ports:
netstat -plant | grep '80\|443'
- At last, confirm if ufw enables TCP connections on port 80 and 443:
ufw status
Other troubles with the server:
- The Index File is Incorrect
- Permissions have been set incorrectly.
Error 403: Client-Side Cause
As previously stated, the 403 error can also be caused by the user rather than the server. Undertake the basic operations on the client side to fix such problems.
- Make sure you are attempting to access the target web location
- Clear the cache in your browser.
- Ensure that you can access the web resource through the firewall or proxy.
Are you looking for an answer to another query? Contact our technical support team.