From 27a9f9d3f8443ebcd520eb0b0253bd383272e16c Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Tue, 23 Aug 2016 00:32:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B2=D0=BD=D1=83=D1=82=D1=80=D0=B5=D0=BD=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20=D1=80=D0=B5=D0=B4=D0=B8=D1=80=D0=B5=D0=BA=D1=82=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=B5=D0=B9=D1=81=D0=B0,=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B3=D0=B4=D0=B0=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81?= =?UTF-8?q?=20=D0=B1=D1=83=D0=B4=D0=B5=D1=82=20=D0=B8=D0=B4=D1=82=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D1=82=D0=B0=D1=80=D1=8B=D0=B9=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BC=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 2 + docker/nginx/Dockerfile | 7 +++ docker/nginx/account.ely.by.conf.template | 54 +++++++++++++++++++++++ docker/nginx/nginx.conf | 44 +----------------- docker/nginx/run.sh | 4 ++ 5 files changed, 68 insertions(+), 43 deletions(-) create mode 100644 docker/nginx/account.ely.by.conf.template create mode 100644 docker/nginx/run.sh diff --git a/docker-compose.yml b/docker-compose.yml index 7af9011..3a4285c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,6 +20,8 @@ services: - app volumes_from: - app + environment: + - AUTHSERVER_HOST=authserver.ely.by node-dev-server: build: ./frontend diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile index 231bba4..e7f976e 100644 --- a/docker/nginx/Dockerfile +++ b/docker/nginx/Dockerfile @@ -1,3 +1,10 @@ FROM nginx:1.9 COPY nginx.conf /etc/nginx/nginx.conf +COPY account.ely.by.conf.template /etc/nginx/conf.d/account.ely.by.conf.template +COPY run.sh /run.sh + +RUN rm /etc/nginx/conf.d/default.conf \ + && chmod a+x /run.sh + +CMD ["/run.sh"] diff --git a/docker/nginx/account.ely.by.conf.template b/docker/nginx/account.ely.by.conf.template new file mode 100644 index 0000000..6bc993f --- /dev/null +++ b/docker/nginx/account.ely.by.conf.template @@ -0,0 +1,54 @@ +server { + listen 80; + + set $root_path '/var/www/html'; + set $api_path '${root_path}/api/web'; + set $frontend_path '${root_path}/frontend/dist'; + set $authserver_host '${AUTHSERVER_HOST}'; + + root $root_path; + charset utf-8; + client_max_body_size 2M; + etag on; + + set $request_url $request_uri; + if ($host = $authserver_host) { + set $request_url '/api/authserver${request_uri}'; + } + + location / { + if ($host = $authserver_host) { + rewrite ^ /api/authserver$uri last; + } + + alias $frontend_path; + index index.html; + try_files $uri /index.html =404; + } + + location /api { + try_files $uri $uri /api/web/index.php?$is_args$args; + } + + location ~* \.php$ { + fastcgi_pass app:9000; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SERVER_NAME $host; + fastcgi_param REQUEST_URI $request_url; + try_files $uri =404; + } + + # html файлы идут отдельно, для них будет применяться E-Tag кэширование + location ~* \.html$ { + root $frontend_path; + access_log off; + } + + # Раздача статики для frontend с указанием max-кэша. Сброс будет по #hash после ребилда webpackом + location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|json|css|zip|rar|eot|ttf|woff|ico) { + root $frontend_path; + expires max; + access_log off; + } +} diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf index a8e1609..886547e 100644 --- a/docker/nginx/nginx.conf +++ b/docker/nginx/nginx.conf @@ -21,47 +21,5 @@ http { sendfile on; keepalive_timeout 10; - server { - listen 80; - - set $root_path '/var/www/html'; - set $api_path '${root_path}/api/web'; - set $frontend_path '${root_path}/frontend/dist'; - - root $root_path; - charset utf-8; - client_max_body_size 2M; - etag on; - - location / { - alias $frontend_path; - index index.html; - try_files $uri /index.html =404; - } - - location /api { - try_files $uri /api/web/index.php?$args; - } - - location ~* \.php$ { - fastcgi_pass app:9000; - include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param SERVER_NAME $host; - } - - # html файлы идут отдельно, для них будет применяться E-Tag кэширование - location ~* \.html$ { - root $frontend_path; - access_log off; - } - - # Раздача статики для frontend с указанием max-кэша. Сброс будет по #hash после ребилда webpackом - location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|json|css|zip|rar|eot|ttf|woff|ico) { - root $frontend_path; - expires max; - access_log off; - } - } - + include /etc/nginx/conf.d/*.conf; } diff --git a/docker/nginx/run.sh b/docker/nginx/run.sh new file mode 100644 index 0000000..ba8bc4c --- /dev/null +++ b/docker/nginx/run.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +envsubst '$AUTHSERVER_HOST' < /etc/nginx/conf.d/account.ely.by.conf.template > /etc/nginx/conf.d/default.conf +nginx -g 'daemon off;'