diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf deleted file mode 100644 index 4664a79a3..000000000 --- a/docker/nginx/default.conf +++ /dev/null @@ -1,52 +0,0 @@ - -## FRONTEND ## -server { - listen 80 default; - - root /app/frontend/web; - index index.php index.html; - - server_name localhost; - - charset utf-8; - - # location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|js)$ { - # access_log off; - # expires max; - # } - - location / { - try_files $uri $uri/ /index.php?$args; - } - - client_max_body_size 32m; - - # There is a VirtualBox bug related to sendfile that can lead to - # corrupted files, if not turned-off - # sendfile off; - - location ~ \.php$ { - fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_pass php-fpm; - fastcgi_index index.php; - include fastcgi_params; - - ## Cache - # fastcgi_pass_header Cookie; # fill cookie valiables, $cookie_phpsessid for exmaple - # fastcgi_ignore_headers Cache-Control Expires Set-Cookie; # Use it with caution because it is cause SEO problems - # fastcgi_cache_key "$request_method|$server_addr:$server_port$request_uri|$cookie_phpsessid"; # generating unique key - # fastcgi_cache fastcgi_cache; # use fastcgi_cache keys_zone - # fastcgi_cache_path /tmp/nginx/ levels=1:2 keys_zone=fastcgi_cache:16m max_size=256m inactive=1d; - # fastcgi_temp_path /tmp/nginx/temp 1 2; # temp files folder - # fastcgi_cache_use_stale updating error timeout invalid_header http_500; # show cached page if error (even if it is outdated) - # fastcgi_cache_valid 200 404 10s; # cache lifetime for 200 404; - # or fastcgi_cache_valid any 10s; # use it if you want to cache any responses - } -} - - -## PHP-FPM Servers ## -upstream php-fpm { - server app:9000; -} diff --git a/docker/nginx/vhost.conf b/docker/nginx/vhost.conf new file mode 100644 index 000000000..7d92c0836 --- /dev/null +++ b/docker/nginx/vhost.conf @@ -0,0 +1,150 @@ +## API ## +server { + listen 80; + + root /app/api/web; + index index.php index.html; + + server_name api.yii2-starter-kit.localhost; + + charset utf-8; + + location / { + try_files $uri $uri/ /index.php?$args; + } + + client_max_body_size 32m; + + # There is a VirtualBox bug related to sendfile that can lead to + # corrupted files, if not turned-off + # sendfile off; + + location ~ \.php$ { + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_pass php-fpm; + fastcgi_index index.php; + include fastcgi_params; + } +} + +## FRONTEND ## +server { + listen 80 default; + + root /app/frontend/web; + index index.php index.html; + + server_name yii2-starter-kit.localhost; + + charset utf-8; + + # location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|js)$ { + # access_log off; + # expires max; + # } + + location / { + try_files $uri $uri/ /index.php?$args; + } + + client_max_body_size 32m; + + # There is a VirtualBox bug related to sendfile that can lead to + # corrupted files, if not turned-off + # sendfile off; + + location ~ \.php$ { + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_pass php-fpm; + fastcgi_index index.php; + include fastcgi_params; + + ## Cache + # fastcgi_pass_header Cookie; # fill cookie valiables, $cookie_phpsessid for exmaple + # fastcgi_ignore_headers Cache-Control Expires Set-Cookie; # Use it with caution because it is cause SEO problems + # fastcgi_cache_key "$request_method|$server_addr:$server_port$request_uri|$cookie_phpsessid"; # generating unique key + # fastcgi_cache fastcgi_cache; # use fastcgi_cache keys_zone + # fastcgi_cache_path /tmp/nginx/ levels=1:2 keys_zone=fastcgi_cache:16m max_size=256m inactive=1d; + # fastcgi_temp_path /tmp/nginx/temp 1 2; # temp files folder + # fastcgi_cache_use_stale updating error timeout invalid_header http_500; # show cached page if error (even if it is outdated) + # fastcgi_cache_valid 200 404 10s; # cache lifetime for 200 404; + # or fastcgi_cache_valid any 10s; # use it if you want to cache any responses + } +} + +## BACKEND ## +server { + listen 80; + + root /app/backend/web; + index index.php index.html; + + server_name backend.yii2-starter-kit.localhost; + + charset utf-8; + + client_max_body_size 16m; + + # There is a VirtualBox bug related to sendfile that can lead to + # corrupted files, if not turned-off on Vagrant based setup + # sendfile off; + + location / { + try_files $uri $uri/ /index.php?$args; + } + + # location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|js)$ { + # access_log off; + # expires max; + # } + + location ~ \.php$ { + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_pass php-fpm; + fastcgi_index index.php; + include fastcgi_params; + } + +} + +## STORAGE ## +server { + listen 80; + server_name storage.yii2-starter-kit.localhost; + + root /app/storage/web; + index index.html; + # expires max; + + # There is a VirtualBox bug related to sendfile that can lead to + # corrupted files, if not turned-off + # sendfile off; + + location / { + try_files $uri $uri/ /index.php?$args; + } + + location ~ \.php$ { + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_pass php-fpm; + fastcgi_index index.php; + include fastcgi_params; + } +} + +## PHP-FPM Servers ## +upstream php-fpm { + server app:9000; +} + +## MISC ## +### WWW Redirect ### +server { + listen 80; + server_name www.yii2-starter-kit.localhost; + return 301 http://yii2-starter-kit.localhost$request_uri; +} diff --git a/docker/nginx_single_domain/vhost.conf b/docker/nginx/vhost_single_domain.conf similarity index 100% rename from docker/nginx_single_domain/vhost.conf rename to docker/nginx/vhost_single_domain.conf diff --git a/pwd-compose.yml b/pwd-compose.yml index 467e4a7fd..144297b09 100644 --- a/pwd-compose.yml +++ b/pwd-compose.yml @@ -39,7 +39,7 @@ services: - 80:80 volumes: - starter_kit_app:/app - command: sh -c "cp /app/docker/nginx/default.conf /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" + command: sh -c "cp /app/docker/nginx/vhost.conf /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" depends_on: - app - source