jwilder/nginx 禁止授予 403 权限
jwilder/nginx giving 403 permission forbidden
我正在尝试使用带有 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 directory index of "/app/" is forbidden..
尝试按照 this SO post 删除 $uri/ 但这给我留下了重定向周期。现在我想看看我是否可以设置正确的权限,但我很挣扎
我错过了什么?
您好,很简单,您的容器 /app/index.html 里面
我的问题是一个基本的误解,即反向代理可以进入我的容器的文件系统,正如 jwilder 自己所说 here。
因此,在我的例子中,反向代理上的默认位置是不必要的。相反,我可以简单地让它指向我的容器,并让我容器中的 nginx 配置确定我的应用程序的位置。
我正在尝试使用带有 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 directory index of "/app/" is forbidden..
尝试按照 this SO post 删除 $uri/ 但这给我留下了重定向周期。现在我想看看我是否可以设置正确的权限,但我很挣扎
我错过了什么?
您好,很简单,您的容器 /app/index.html 里面
我的问题是一个基本的误解,即反向代理可以进入我的容器的文件系统,正如 jwilder 自己所说 here。
因此,在我的例子中,反向代理上的默认位置是不必要的。相反,我可以简单地让它指向我的容器,并让我容器中的 nginx 配置确定我的应用程序的位置。