简体   繁体   中英

How to create a LEMP stack with docker-compose?

i want to create a LEMP stack with docker-compose for local web development but i've got in some troubles...

The configuration files i wrote:

docker-compose.yml

nginx:
        image: nginx:latest
        ports:
                - "8080:80"
        volumes:
                - ./web:/web
                - ./mysite.template:/etc/nginx/conf.d/mysite.template
        links:
                - php
        command: /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
php:
        image: php:7-fpm
        volumes:
                - ./web:/web

mysite.template

server {
        listen 80;
        root /web;
        index index.php index.html;
        server_name default_server;

     location ~ \.php$ {
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /web$fastcgi_script_name;
        }
}

The problem is that when i try to open http://localhost:8080 the result is an Access Denied

How can i fix it?

EDIT:
This is the nginx container error log:

nginx_1  | 2017/11/01 13:21:25 [error] 8#8: *1 FastCGI sent in stderr: "Access to the script '/web' has been denied (see security.limit_extensions)" while reading response header from upstream

I was able to get your example working by changing your docker-compose.yml to:

nginx:
        image: nginx:latest
        ports:
                - "8080:80"
        volumes:
                - ./web:/web
                - ./mysite.template:/etc/nginx/conf.d/default.conf
        links:
                - php
php:
        image: php:7-fpm
        volumes:
                - ./web:/web

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM