Nginx serve static file and got 403 forbidden

后端 未结 8 954
长情又很酷
长情又很酷 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

    Setting user root in nginx can be really dangerous. Having to set permissions to all file hierarchy can be cumbersome (imagine the folder's full path is under more than 10 subfolders).

    What I'd do is to mirror the folder you want to share, under /usr/share/nginx/any_folder_name with permissions for nginx's configured user (usually www-data). That you can do with bindfs.

    In your case I would do:

    sudo bindfs -u www-data -g www-data /root/downloads/boxes/ /usr/share/nginx/root_boxes
    

    It will mount /root/downloads/boxes into /usr/share/nginx/root_boxes with all permissions for user www-data. Now you set that path in your location block config

    location /static {
       autoindex on;
       alias /usr/share/nginx/root_boxes/;
      }
    

提交回复
热议问题