Solve the 403 forbidden in Nginx

Reference blog: http://blog.csdn.net/onlysunnyboy/article/details/75270533

When configuring the static page of nignx

server {
    listen       80;
    server_name  localhost;
    #Some configuration content is omitted here
    location / {
        #root   html;
        #index  index.html index.htm;
        root /home/myapp/;
        index index.html;
    }
    #Some configuration content is omitted here
}
After the configuration is complete, open nignx and report a 403 forbidden error.

The main reason for the error is: permission issues.

1. Due to the inconsistency between the startup user and the nginx working user (effective for personal testing)
1. View the configuration file nginx.conf

first row

#user  nobody;
2. Change it to, root is the user I am currently logged in. If you log in with another user name, please change it to the same name as the login name.

user  root;
Second, the directory permission problem, if nginx does not have the operation permission of the web directory, a 403 error will also occur.

Solution: Modify the read and write permissions of the web directory, or change the startup user of nginx to the user of the directory, and restart Nginx to solve the problem.

chmod -R 777 /data




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325734479&siteId=291194637