【问题标题】:jwilder/nginx giving 403 permission forbiddenjwilder/nginx 给予 403 权限被禁止
【发布时间】:2020-02-15 12:23:11
【问题描述】:

我正在尝试使用带有 nginx 反向代理的静态 index.html 文件为多个容器提供服务

我已尝试按照文档 here 创建默认位置

location / {
  root   /app;
  index  index.html;
  try_files $uri $uri/ /index.html;
}

如果我在容器中检查我的 default.conf

$ docker-compose exec nginx-proxy cat /etc/nginx/conf.d/default.conf

我得到这个结果:

server {
        server_name _; # This is just an invalid value which will never trigger on a real hostname.
        listen 80;
        access_log /var/log/nginx/access.log vhost;
        return 503;
}
# xx.example.services
upstream xx.example.services {
                                ## Can be connected with "nginx-proxy" network
                        # examplecontainer1
                        server 172.18.0.4:80;
}
server {
        server_name xx.example.services;
        listen 80 ;
        access_log /var/log/nginx/access.log vhost;
        location / {
                proxy_pass http://xx.example.services;
                include /etc/nginx/vhost.d/default_location;
        }
}
# yy.example.services
upstream yy.example.services {
                                ## Can be connected with "nginx-proxy" network
                        # examplecontainer2
                        server 172.18.0.2:80;
}
server {
        server_name yy.example.services;
        listen 80 ;
        access_log /var/log/nginx/access.log vhost;
        location / {
                proxy_pass http://yy.example.services;
                include /etc/nginx/vhost.d/default_location;
        }
}

如果我检查 /etc/nginx/vhost.d/default_location 的内容,这正是我一开始输入的内容,所以没关系

但是,当我访问 xx.example.services 时,我得到了 403 禁止。

据我了解,这意味着没有找到 index.html 文件,但如果我执行到我的容器中并且 cat app/index.html 它确实存在!

我已经检查过我的所有容器都在同一个网络上。

我正在使用这个命令运行我的容器

docker run -d --name examplecontainer1 --expose 80 --net nginx-proxy -e VIRTUAL_HOST=xx.example.services my-container-registry

更新 我检查了我的 nginx-proxy 容器的日志,发现了这个错误消息:

[error] 29#29: *1 目录索引“/app/”被禁止..

尝试按照this SO post 删除 $uri/ 但这只是给我留下了重定向周期。现在我正在尝试查看是否可以设置正确的权限,但我很挣扎

我错过了什么?

【问题讨论】:

    标签: docker nginx reverse-proxy jwilder-nginx-proxy


    【解决方案1】:

    我的问题是一个基本的误解,即反向代理可以进入我的容器的文件系统,正如 jwilder 本人所说的 here

    因此,在我的情况下,反向代理上的默认位置是不必要的。相反,我可以简单地让它指向我的容器,并让容器中的 nginx 配置确定我的应用程序的位置。

    【讨论】:

      【解决方案2】:

      您好,很简单,您的容器中缺少 /app/index.html

      【讨论】:

      • 那么当我写“docker exec examplecontainer1 cat app/index.html”时如何查看内容?
      • 以及该容器的配置或文件的权限?
      猜你喜欢
      • 2017-05-16
      • 2019-01-23
      • 2020-07-07
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 2016-04-21
      • 1970-01-01
      相关资源
      最近更新 更多