Nginx serve static file and got 403 forbidden

后端 未结 8 951
长情又很酷
长情又很酷 2020-12-04 08:36

Just want to help somebody out. yes ,you just want to serve static file using nginx, and you got everything right in nginx.conf:

location /s         


        
8条回答
  •  眼角桃花
    2020-12-04 08:40

    You should give nginx permissions to read the file. That means you should give the user that runs the nginx process permissions to read the file.

    This user that runs the nginx process is configurable with the user directive in the nginx config, usually located somewhere on the top of nginx.conf:

    user www-data
    

    http://wiki.nginx.org/CoreModule#user

    The second argument you give to user is the group, but if you don't specify it, it uses the same one as the user, so in my example the user and the group both are www-data.

    Now the files you want to serve with nginx should have the correct permissions. Nginx should have permissions to read the files. You can give the group www-data read permissions to a file like this:

    chown :www-data my-file.html
    

    http://linux.die.net/man/1/chown

    with chown you can change the user and group owner of a file. In this command I only change the group, if you would change the user too you would specify the username BEFORE the colon, like chown www-data:www-data my-file.html. But setting the group permissions correct should be enough for nginx to be able to read the file.

提交回复
热议问题