【发布时间】: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