How to fix Nginx error 403 Forbidden


If you get error 403 Forbidden for all exist files on your server when you use Nginx. Eg: you use VPS of Digital Ocean.

403 Forbidden

nginx/1.12.2

nginx 403 forbidden

How to fix this problem ?

Step 1: check if SELinux is running

getenforce

Result for VPS Digital Ocean

[root@tutorialspots ~]# getenforce
Enforcing

Result for VPS Vultr

[root@tutorialspots ~]# getenforce
Disabled

Step 2: disable SELinux until next reboot

setenforce Permissive

Step 3: (optinal) restart nginx, done!

But after next reboot, you must do step 2 and 3 again. So, you should do step 4:

Step 4: edit file /etc/sysconfig/selinux

[root@tutorialspots ~]# cat /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are pro
tected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

Use vi or nano to edit that file.

Leave a Reply