diff --git a/Resources/compose/docker-compose-prod-graphql.yml b/Resources/compose/docker-compose-prod-graphql.yml index d50c8e58..0be52216 100644 --- a/Resources/compose/docker-compose-prod-graphql.yml +++ b/Resources/compose/docker-compose-prod-graphql.yml @@ -5,9 +5,6 @@ services: POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}" POSTGRES_USER: "${POSTGRES_USER}" - app: - env_file: .env - web: volumes: - graphiql:/public-console:ro diff --git a/Resources/nginx/nginx.conf b/Resources/nginx/nginx.conf index 4c3763c7..ff2e4a7f 100644 --- a/Resources/nginx/nginx.conf +++ b/Resources/nginx/nginx.conf @@ -1,7 +1,7 @@ -worker_processes 2; +worker_processes 1; events { - worker_connections 4096; + worker_connections 1024; multi_accept on; # accept each connection as soon as you can accept_mutex off; use epoll; @@ -29,16 +29,16 @@ http { gzip_disable "msi6"; gzip_vary on; gzip_proxied any; - gzip_comp_level 6; + gzip_comp_level 4; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_min_length 256; gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml; - upstream pokeapi_upstream { + #upstream pokeapi_upstream { # 'app' is the Django container name in Docker - server app:80 fail_timeout=0; - } + # server app:80 fail_timeout=0; + #} upstream graphql_upstream { server graphql-engine:8080 fail_timeout=0; @@ -57,6 +57,7 @@ http { limit_req_zone $limit_key zone=graphqlDefaultLimit:50m rate=1r/m; limit_conn_zone $binary_remote_addr zone=addr:20m; + proxy_cache_path /tmp/cache levels=1:2 keys_zone=small:40m inactive=10d max_size=2g use_temp_path=off; server { listen 80 deferred; @@ -67,7 +68,7 @@ http { client_body_timeout 5s; client_header_timeout 5s; - limit_conn addr 10; + limit_conn addr 15; # Admin console location /graphql/admin/ { @@ -91,11 +92,19 @@ http { } location /graphql/v1beta { + proxy_read_timeout 70s; + proxy_cache small; + proxy_cache_valid 200 10d; + proxy_cache_valid any 0; + proxy_cache_methods POST; + proxy_cache_key "$request_method$request_uri$request_body"; limit_req zone=graphqlDefaultLimit burst=100 nodelay; limit_req_status 429; - expires 1m; # client-side caching, one minute for each API resource + expires 30m; # client-side caching, one minute for each API resource add_header Cache-Control "public"; add_header Pragma public; + add_header X-Proxy-Cache $upstream_cache_status; + add_header X-Cache-Date $upstream_http_date; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; @@ -106,23 +115,9 @@ http { proxy_pass http://graphql_upstream/v1/graphql; } - location /api/ { - expires 1m; # client-side caching, one minute for each API resource - add_header Cache-Control "public"; - add_header Pragma public; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_redirect off; - proxy_pass http://pokeapi_upstream; - } location / { - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_redirect off; - proxy_pass http://pokeapi_upstream; + return 404; } } } diff --git a/docker-compose.yml b/docker-compose.yml index 433c8b33..9d34cf87 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,25 +16,6 @@ services: - pg_data:/var/lib/postgresql/data restart: always - app: - build: - context: . - dockerfile: ./Resources/docker/app/Dockerfile - user: ${RUN_AS:-pokeapi} - environment: - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-pokemon} - POSTGRES_USER: ${POSTGRES_USER:-ash} - POSTGRES_DB: ${POSTGRES_DB:-pokeapi} - volumes: - - .:/code - links: - - db - - cache - depends_on: - - db - - cache - restart: always - web: image: nginx:alpine ports: @@ -45,13 +26,12 @@ services: volumes: - ./Resources/nginx/nginx.conf:/etc/nginx/nginx.conf:ro - ./Resources/nginx/ssl:/ssl:ro - volumes_from: - - app:ro - links: - - app graphql-engine: image: hasura/graphql-engine:v2.0.0-alpha.5 + cpus: 0.7 + memswap_limit: 3g + mem_limit: 450m ports: - "8080:8080" depends_on: