这是我的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/工作,在/ code文件夹中显示文件index.html
但是它不适用于http://nginx-php-docker.local:8081/html
错误日志为:
2017/01/13 08:50:27 [错误] 7#7:* 4 open()“/ usr / share / nginx / html / html”失败(2:无此类文件或目录),客户端:172.19.0.1 ,服务器:本地主机,请求:“GET / html HTTP / 1.1”,主机:“nginx-php-docker.local:8081”
请告诉我我哪里错了。
最佳答案
您正在配置nginx容器以侦听site.conf
中的8081端口,因为图像公开了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
关于nginx - 使用Nginx的docker-compose无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41630649/