1

This is my 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

And this is site.conf

server {

   listen 8081;
   index index.html index.php;
   server_name localhost;
   error_log  /var/log/nginx/error.log;

   location /html {
       root /myapp;
   }
}

It works on http://nginx-php-docker.local:8081/, showing the file index.html which is inside the /code folder.

But It is not working with http://nginx-php-docker.local:8081/html

The error log is

2017/01/13 08:50:27 [error] 7#7: 
  *4 open() "/usr/share/nginx/html/html" failed (2: No such file or directory), 
    client: 172.19.0.1, 
    server: localhost, 
    request: "GET /html HTTP/1.1", 
    host: "nginx-php-docker.local:8081"
winklerrr
  • 13,026
  • 8
  • 71
  • 88
anhduc.bkhn
  • 695
  • 3
  • 10
  • 21

3 Answers3

9

You are configuring the nginx container to listen on port 8081 in site.conf, this makes no sense since the image exposes port 80 and 443.

Change your site.conf to:

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;
   }
}

And the following line in docker-compose.yml:

volumes:  
  - ./site.conf:/etc/nginx/conf.d/default.conf
rckrd
  • 3,124
  • 1
  • 13
  • 23
  • I got another issue with mysql container, please help http://stackoverflow.com/questions/41671935/php-cannot-connect-to-mysql-in-docker-compose – anhduc.bkhn Jan 16 '17 at 08:15
0

Edit you'r compose file to be like this ,, you are redirecting the html file to the wrong directory

version: '2' 

services: 

nginx:

image: nginx:1.11.8-alpine
ports:
  - "8081:80"
volumes:
  - ./code:/var/www/html/
  - ./html:/myapp
  - ./site.conf:/etc/nginx/conf.d/site.conf
  - ./error.log:/var/log/nginx/error.log
  - ./nginx.conf:/etc/nginx/nginx.conf
Tyr_90
  • 31
  • 1
  • 9
-3

In your terminal run the command:

sudo setenfonce 0

Now, re-run the docker command.

Marcus Pereira
  • 220
  • 3
  • 11