Nginx serve static file and got 403 forbidden

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

    Try the accepted answer by @gitaarik, and if it still gives 403 Forbidden or 404 Not Found and your location target is / read on.

    I also experienced this issue, but none of the permission changes mentioned above solved my problem. It was solved by adding the root directive because I was defining the root location (/) and accidentally used the alias directive when I should have used the root directive.

    The configuration is accepted, but gives 403 Forbidden, or 404 Not Found if auto-indexing is enabled for /:

    location / {
      alias /my/path/;
      index index.html;
    }
    

    Correct definition:

    location / {
      root /my/path/;
      index index.html;
    }
    
    0 讨论(0)
  • 2020-12-04 08:59

    I bang my head on this 403 problem for quite some time. I'm using CentOS from DigitalOcean.

    I thought to fix the problem was just to set SELINUX=disabled in /etc/selinux/config but I was wrong. Somehow, I screwed my droplet.

    This works for me! sudo chown nginx:nginx /var/www/mydir

    0 讨论(0)
提交回复
热议问题