diff --git a/.env.dist b/.env.dist index ee55e182..681ecfef 100644 --- a/.env.dist +++ b/.env.dist @@ -1,6 +1,9 @@ # Symfony application's path (absolute or relative) SYMFONY_APP_PATH=../path/to/symfony/folder +# Symfony application's host +NGINX_HOST=symfony.local + # MySQL MYSQL_ROOT_PASSWORD=root MYSQL_DATABASE=mydb diff --git a/README.md b/README.md index d4d4db14..e8255eda 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,11 @@ Docker-symfony gives you everything you need for developing Symfony application. $ docker-compose up -d ``` -3. Update your system host file (add symfony.local) +3. Update your system host file (add value you've assigned to NGINX_HOST environmental variable) ```bash # UNIX only: get containers IP address and update host (replace IP according to your configuration) (on Windows, edit C:\Windows\System32\drivers\etc\hosts) - $ sudo echo $(docker network inspect bridge | grep Gateway | grep -o -E '[0-9\.]+') "symfony.local" >> /etc/hosts + $ sudo echo $(docker network inspect bridge | grep Gateway | grep -o -E '[0-9\.]+') "yourhostname" >> /etc/hosts ``` **Note:** For **OS X**, please take a look [here](https://docs.docker.com/docker-for-mac/networking/) and for **Windows** read [this](https://docs.docker.com/docker-for-windows/#/step-4-explore-the-application-and-run-examples) (4th step). diff --git a/docker-compose.yml b/docker-compose.yml index 90cd989e..d4b87cb7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,13 +19,17 @@ services: - ${SYMFONY_APP_PATH}:/var/www/symfony - ./logs/symfony:/var/www/symfony/app/logs nginx: - build: nginx + image: nginx ports: - 80:80 volumes_from: - php volumes: + - ./nginx/default.template:/etc/nginx/conf.d/default.template - ./logs/nginx/:/var/log/nginx + environment: + - NGINX_HOST=${NGINX_HOST} + command: /bin/sh -c "envsubst '$$NGINX_HOST' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" elk: image: willdurand/elk ports: diff --git a/nginx/Dockerfile b/nginx/Dockerfile deleted file mode 100644 index 8011b3ab..00000000 --- a/nginx/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM debian:jessie - -MAINTAINER Maxence POUTORD - -RUN apt-get update && apt-get install -y \ - nginx - -ADD nginx.conf /etc/nginx/ -ADD symfony.conf /etc/nginx/sites-available/ - -RUN ln -s /etc/nginx/sites-available/symfony.conf /etc/nginx/sites-enabled/symfony -RUN rm /etc/nginx/sites-enabled/default - -RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf - -RUN usermod -u 1000 www-data - -CMD ["nginx"] - -EXPOSE 80 -EXPOSE 443 diff --git a/nginx/symfony.conf b/nginx/default.template similarity index 80% rename from nginx/symfony.conf rename to nginx/default.template index f17c5539..a8dd24ac 100644 --- a/nginx/symfony.conf +++ b/nginx/default.template @@ -1,5 +1,7 @@ server { - server_name symfony.local; + listen 80 default_server; + listen [::]:80 default_server; + server_name ${NGINX_HOST}; root /var/www/symfony/web; location / { @@ -11,7 +13,7 @@ server { } location ~ ^/(app|app_dev|config)\.php(/|$) { - fastcgi_pass php-upstream; + fastcgi_pass php:9000; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; diff --git a/nginx/nginx.conf b/nginx/nginx.conf deleted file mode 100644 index a9ecf0e5..00000000 --- a/nginx/nginx.conf +++ /dev/null @@ -1,29 +0,0 @@ -user www-data; -worker_processes 4; -pid /run/nginx.pid; - -events { - worker_connections 2048; - multi_accept on; - use epoll; -} - -http { - server_tokens off; - sendfile on; - tcp_nopush on; - tcp_nodelay on; - keepalive_timeout 15; - types_hash_max_size 2048; - include /etc/nginx/mime.types; - default_type application/octet-stream; - access_log off; - error_log off; - gzip on; - gzip_disable "msie6"; - include /etc/nginx/conf.d/*.conf; - include /etc/nginx/sites-enabled/*; - open_file_cache max=100; -} - -daemon off;