nginx索引指令在本地工作正常,但ec2上给404
我有一个web项目,我想用docker-compose和nginx来部署。
我在本地,
docker-compose build docker-compose push
如果我是docker-compose up
,我可以访问localhost/
并redirect到我的index.html
。
现在在我的EC2实例(我安装了docker和docker-compose的一个常规ec2实例)中, docker-compose pull
,然后是docker-up。
所有的容器都可以正常启动,我可以exec sh
到我的nginx容器中,看到有一个/facebook/index.html
文件。
- 如果我去
[instance_ip]/index.html
,一切都按预期工作。 - 如果我去
[instance_ip]/
,我得到一个404响应。
nginx收到请求(我在访问日志中看到它),但不会redirect到index.html
。
为什么index
指令不能redirect到我的index.html
文件?
我尝试过了:
- 通过删除所有本地图像并从我的registry中提取本地重现。
- 杀死我的EC2实例,并启动一个新的。
但是我得到了同样的结果。
我使用docker-compose 1.11.1和docker 17.05.0。 在ec2实例上,它是docker 17.03.1,我试了两个docker-compose 1.11.1和1.14.1(注意我有点绝望;))。
来自我的docker-compose文件的摘录:
nginx: image: [image from registry] build: context: ./ dockerfile: deploy/nginx.dockerfile ports: - "80:80" depends_on: - web
我的nginx镜像从alpine开始,安装nginx,添加index.html文件,并将我的conf文件复制到/etc/nginx/nginx.conf
。
这是我的nginxconfiguration。 我检查它在运行的容器上(包括本地和ec2上)。
# prevent from exiting when using `run` to launch container daemon off; worker_processes auto; # pid /run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings sendfile off; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; server { error_log /var/log/nginx/file.log debug; listen 80 default_server; # root /home/domain.com; # Bad developers use underscore in headers. underscores_in_headers on; # root should be out of location block root /facebook; location / { index index.html; # autoindex on; try_files $uri @app; } location @app { include uwsgi_params; # Using docker-compose linking, the nginx docker-compose service depends on a 'web' service. uwsgi_pass web:3033; } } }
我不知道为什么容器在EC2实例上的行为不同。
任何指针赞赏!