Nginx: stat() failed (13: permission denied)

解决

复制代码
server {
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        #root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                root /root/test/dist;
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.html;
        }

……
}

首先确定将 root 指定的目录权限改为 775

复制代码
chmod -R 775 /root/test/dist;

然后将 nginx.conf 文件的 user 设置为 root

如果你想用默认的 www-data 用户,需要将 www-data 添加到 username 组中:

复制代码
gpasswd -a www-data username

确保 username 组可以沿着路径输入所有目录:

复制代码
chmod g+x /root && chmod g+x /root/test/dist

运行 stat 看看是否成功:

复制代码
sudo -u www-data stat /root/test/dist

检查 nginx 配置

复制代码
nginx -t

重启 nginx

复制代码
nginx -s reload
posted @   牛奔  阅读(333)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2021-05-28 go map fatal error: concurrent map iteration and map write 读写锁与深度拷贝的坑
2021-05-28 vue 判断某个时间小于当前时间
2021-05-28 elmentui input number 数字验证
2019-05-28 HTTP与HTTPS的区别
点击右上角即可分享
微信分享提示