diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..4fb07b5 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,41 @@ +services: + app: + restart: unless-stopped + build: + context: . + env_file: + - ./.env + volumes: + - ./src/:/app/src/ + - ./config/:/app/config/ + - ./storage/:/app/storage/ + - ./public/:/app/public/ + logging: + driver: 'json-file' + options: + max-size: '50m' +# networks: +# - default + nginx: + image: 'nginx:latest' + restart: unless-stopped + ports: + - '8080:80' + volumes: + - ./public:/var/www/public/ + - ./nginx/conf.d/:/etc/nginx/conf.d/ + - ./nginx/nginx.conf:/etc/nginx/nginx.conf + - ./cache/:/var/cache/ + depends_on: + - app + logging: + driver: 'json-file' + options: + max-size: '50m' +# networks: +# - default +# - web +#networks: +# web: +# external: true +# name: web diff --git a/nginx/conf.d/app.conf b/nginx/conf.d/app.conf new file mode 100644 index 0000000..54e89e9 --- /dev/null +++ b/nginx/conf.d/app.conf @@ -0,0 +1,77 @@ +map $sent_http_content_type $expires { + "text/html" epoch; + "text/html; charset=utf-8" epoch; + "application/javascript" 365d; + "text/css" 365d; + "text/css; charset=utf-8" 365d; + default off; +} + +map $args $skip_static { + "" 0; + default 1; +} + +upstream app { + server app:8080; +} + +server { + listen 80; + index index.php index.html; + error_log /var/log/nginx/error.log; + access_log /var/log/nginx/access.log; + root /var/www/public; + client_max_body_size 20M; + + gzip on; + gzip_comp_level 5; + gzip_disable "msie6"; + gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript; + + location / { + location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|woff|woff2|eot|txt)$ { + try_files $uri $uri/ =404; + expires 365d; + } + location /robots.txt { + try_files /robots.txt @fallback; + gzip_static on; + } + location / { + proxy_cache local_cache; + proxy_cache_valid 200 1h; + proxy_cache_lock on; + + #proxy_cache_bypass $no_cache; + #proxy_no_cache $no_cache; + + add_header X-Proxy-Cache $upstream_cache_status; + + proxy_ignore_headers Cache-Control Set-Cookie Expires; + + proxy_buffers 16 16k; + proxy_buffer_size 32k; + + if ($args) { + proxy_pass http://app; + break; + } + + try_files $uri $uri/ @fallback; + gzip_static on; + } + } + + location @fallback { + expires $expires; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_read_timeout 1m; + proxy_connect_timeout 1m; + proxy_pass http://app; + } +} diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..9979b37 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,33 @@ +user nginx; +worker_processes 5; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 2048; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + sendfile on; + keepalive_timeout 65; + + real_ip_header X-Forwarded-For; + real_ip_recursive on; + set_real_ip_from 172.0.0.0/8; + + proxy_cache_path /var/cache/nginx levels=1:2:2 keys_zone=local_cache:150m inactive=1h max_size=200m; + proxy_cache_key "$scheme$request_method$host$request_uri"; + proxy_cache_use_stale error timeout invalid_header http_500; + proxy_ignore_headers Cache-Control Set-Cookie Expires; + + include /etc/nginx/conf.d/*.conf; +}