nginx - 使用Nginx的docker-compose无法正常工作

标签 nginx docker alpine

这是我的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/

相关文章:

php - LEMP + WordPress 设置失败

node.js - npm : Postinstall not running in docker

python - Hbase Shell收到此错误:fstat未实现,不受支持或无法加载 native 支持

docker - kibana&elasticsearch无法在同一容器的docker下连接

docker - Docker返回10.04和10.10的相同内核版本

python - 无法在 Alpine Docker容器上安装pyorc

python-3.7 - 无法在 python3.7-alpine docker 镜像上安装钟摆

带有 puma 的 Rails 5 ActionCable 的 NGINX 配置

ruby-on-rails - Rails + (Phusion Passenger|Puma|Unicorn|Thin) + (Nginx|Apache) 如何协同工作?

django - 另一个虚拟机上 Gunicorn 的 Nginx conf?