Home > AI > Server > Nginx >

change home directory gets nginx 403 forbidden

Reason 1: no index.html

$ nginx -V // check your prefix location. For example
$ cd /usr/share/nginx/html // There is no index.html file, so
$ vi index.html
  1. check if theuser in nginx.con is root or has permission to read the folder
  2. check if the directory’s permission is 751
  3. check if SWLinux is open (disable it if open)
$ getenforce
$ sestatus (or)

Reason 2: check user in nginx.conf

$ ls -la
$ chmod 751 {file/dir}

–rw-r–r– file and drwxr-xr-x directory permission explained

First characterDescription
-Regular file.
bBlock special file.
cCharacter special file.
dDirectory.
lSymbolic link.
pFIFO.
sSocket.
wWhiteout.
Three permission triads defined what the user/group/others can doFirst triad defines what the owner can doSecond triad explains what the group members can doThird triad defines what other users can do
-rw-r--r--Owner has only read and write permission (rw-)Group has read permission (r--)Others has read permission (r--)
drwxr-xr-xOwner has full permission (rwx)Group has read and execute permission (r-x)Others has read and execute permission (r-x)
// check file state
$ stat file

change owner and group

$ chown owner-user file 
$ chown owner-user:owner-group file
$ chown owner-user:owner-group directory
$ chown options owner-user:owner-group file

Leave a Reply