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"
2

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

1 Comment

I got another issue with mysql container, please help stackoverflow.com/questions/41671935/…
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

Comments

-3

In your terminal run the command:

sudo setenfonce 0

Now, re-run the docker command.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.