2017-01-13 1 views
0

Ceci est mon docker-compose.ymldocker-Compose avec nginx ne fonctionne pas

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 

Et c'est 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/ Il est un travail, un fichier index.html montrant l'intérieur/code dossier

Mais il ne fonctionne pas avec http://nginx-php-docker.local:8081/html

E le journal du journal est: 2017/01/13 08:50:27 [erreur] 7 # 7: * 4 open() "/ usr/share/nginx/html/html" a échoué (2: aucun fichier ou répertoire de ce type), client: 172.19.0.1, serveur: localhost, requête: "GET/html HTTP/1.1", hôte: "nginx-php-docker.local: 8081"

Veuillez me dire où je me trompe.

+0

Comment ressemble votre nginx.conf? – rckrd

+0

@rckrd Il est très simple https://gist.github.com/anhducbkhn/21f2a35db1d9dfb5cbe089f658e36c3f –

Répondre

5

Vous configurez le conteneur nginx pour écouter le port 8081 à site.conf, cela n'a aucun sens puisque l'image expose le port 80 et 443.

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

Et ce qui suit ligne dans docker-compose.yml:

volumes: 
    - ./site.conf:/etc/nginx/conf.d/default.conf 
+0

Merci @rckrd. Tu m'as sauvé. –

+0

Super @ anhduc.bkhn! Veuillez considérer pour marquer une réponse acceptée si une solution a été fournie. – rckrd

+0

J'ai un autre problème avec le conteneur mysql, s'il vous plaît aider http://stackoverflow.com/questions/41671935/php-cannot-connect-to-mysql-in-docker-compose –