【问题标题】:Angular and NGINX permission deniedAngular 和 NGINX 权限被拒绝
【发布时间】:2017-11-17 02:11:50
【问题描述】:

我正在尝试设置 NGINX 以访问 Angular /dist 文件夹,但尽管 chmod -R 755 /path/to/dist 无法使其正常工作...

在我的 NGINX http 块中:

server {
  listen 80;
  server_name dashboard.example.local;

  ssl off;

  gzip on;
  root /path/to/dist/;
  index index.html;

  location /api/ {
    proxy_pass http://127.0.0.1:3000/;
  }
}

我仍然收到此错误"dist/index.html" is forbidden (13: Permission denied)

我已经尝试了在互联网上找到的所有现有解决方案。

编辑:nginx 试图访问的文件是 755

【问题讨论】:

标签: angular nginx permissions


【解决方案1】:

问题实际上与 Mac OS 相关。为了允许 NGINX 操作本地文件,我们需要告诉他充当您的用户。

在 NGINX 模板的顶部,只需输入 user <your-user-name> staff;

【讨论】:

    【解决方案2】:

    已经编译的角度源文件作为文件发送到浏览器作为渲染器(客户端)。该代理传递功能仅适用于开发,我假设您使用 angular cli ng serve 运行它。这可能是您在生产或 dist 文件夹中寻找的内容。

    server{
        ...
        root /path/to/dist
    
        index index.html index.htm index.nginx-debian.html;
    
        location / {
                try_files $uri /index.html;
        }
    }
    

    如果权限仍然被拒绝,请尝试使用 chown 命令将该文件夹所有者更改为 nginx 用户..

    【讨论】:

      猜你喜欢
      • 2018-10-02
      • 1970-01-01
      • 2020-08-25
      • 2021-03-27
      • 2017-11-03
      • 2016-03-26
      • 2020-02-08
      • 2014-03-31
      • 2018-12-15
      相关资源
      最近更新 更多