我的任务是创建 3 层架构,其中包括:
我在直接从 nginx 提供所有静态文件(包括 index.html)时遇到问题
现在我可以访问 localhost:5000 上的 Flask 服务器 但我在 localhost:80 上得到 404
docker-compose :
version: "3.3"
services:
ngnix_my:
build: ./nginx/.
ports:
- "80:80"
links:
- app
depends_on:
- app
networks:
- front_net
app:
build: .
ports:
- "5000:5000"
links:
- es
depends_on:
- es
networks:
- front_net
- back_net
es:
image: elasticsearch:7.13.1
environment:
- discovery.type=single-node
networks:
- back_net
networks:
front_net:
driver: bridge
back_net:
driver: bridge
NGINX Dockerfile:
FROM nginx:1.21.0-alpine
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./to_serve /
RUN sudo chmod -R 777 /templates/index.html
ngnix.conf :
events {} # event context needs to be defined to consider config valid
http {
server {
listen 80 default_server;
location /static {
root /templates/index.html;
}
location / {
proxy_pass http://app:5000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
答案 0 :(得分:0)
好的,根据您的日志和 docker 文件,我认为您的静态文件在
/to_serve/templates/static
而不是 /templates/index.html
因此,将 /static
位置的 nginx 配置更改为:
location /static {
root /to_serve/templates/index.html;
}
再次测试