这是我的docker-compose.yml
version: '2' services: nginx: image: nginx:1.11.8-alpine ports: - "8081:80" volumes: - ./code:/usr/share/nginx/html - ./html:/myapp - ./site.conf:/etc/nginx/conf.d/site.conf - ./error.log:/var/log/nginx/error.log - ./nginx.conf:/etc/nginx/nginx.conf
这是site.conf
server { listen 8081; index index.html index.php; server_name localhost; error_log /var/log/nginx/error.log; location /html { root /myapp; } }
http://nginx-php-docker.local:8081 /这是工作,显示文件index.html里面/代码文件夹
但它无法使用http://nginx-php-docker.local:8081/html
错误日志是:2017/01/13 08:50:27 [错误] 7#7:*4打开()"/ usr/share/nginx/html/html"失败(2:没有这样的文件或目录),客户端:172.19.0.1,server:localhost,request:"GET/html HTTP/1.1",host:"nginx-php-docker.local:8081"
请告诉我哪里错了.
您正在配置nginx容器以侦听端口8081 site.conf
,这没有任何意义,因为该映像公开了端口80和443.
将您更改site.conf
为:
server { listen 80; index index.html index.php; server_name localhost; error_log /var/log/nginx/error.log; location / { root /usr/share/nginx/html; } location /html { alias /myapp; } }
以下行docker-compose.yml
:
volumes: - ./site.conf:/etc/nginx/conf.d/default.conf