From 7775a4d5d5fa4cc700af9b18d130e93f8d40a083 Mon Sep 17 00:00:00 2001 From: zfletch Date: Sat, 29 Feb 2020 08:36:46 -0500 Subject: [PATCH] configure nginx caching --- README.md | 8 ++++---- docker-compose.no-redis.yml | 2 +- docker-compose.yml | 13 +++++++++++-- lib/config.rb | 2 +- nginx.conf | 24 ++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 nginx.conf diff --git a/README.md b/README.md index df8bcbc..a84d549 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ services: morph: image: perseidsproject/morpheus-perseids-api:v2.0.0 ports: - - "1316:1316" + - "1500:1500" ``` The port can be customized using the environment variable `PORT` and the application @@ -74,7 +74,7 @@ MORPHLIB=/path/to/stemlib EXECUTABLE=/path/to/morpheus bundle exec ruby app.rb ### Examples -`http://localhost:1316/raw/greek/a)%2Fnqrwpos`: +`http://localhost:1500/raw/greek/a)%2Fnqrwpos`: ```xml @@ -104,7 +104,7 @@ MORPHLIB=/path/to/stemlib EXECUTABLE=/path/to/morpheus bundle exec ruby app.rb ``` -`http://localhost:1316/raw/latin/cactus`: +`http://localhost:1500/raw/latin/cactus`: ```xml @@ -134,7 +134,7 @@ MORPHLIB=/path/to/stemlib EXECUTABLE=/path/to/morpheus bundle exec ruby app.rb ``` -`http://localhost:1316/raw/greek/a)%2Fnqrwpos?verbose=true`: +`http://localhost:1500/raw/greek/a)%2Fnqrwpos?verbose=true`: ```xml diff --git a/docker-compose.no-redis.yml b/docker-compose.no-redis.yml index a40aea1..a9332b3 100644 --- a/docker-compose.no-redis.yml +++ b/docker-compose.no-redis.yml @@ -6,4 +6,4 @@ services: volumes: - .:/app ports: - - 1316:1316 + - 1500:1500 diff --git a/docker-compose.yml b/docker-compose.yml index 4ac340a..f1ecf15 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,13 +6,22 @@ services: volumes: - .:/app ports: - - 1316:1316 + - 1500:1500 depends_on: - redis environment: - REDIS_ENABLED=true - REDIS_URL=redis://redis:6379 redis: - image: redis:5.0.5 + image: redis:5.0.7 ports: - 6379:6379 + cache: + image: nginx:1.17.8 + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf + - ./tmp/nginx:/var/cache/nginx + ports: + - 1501:1501 + depends_on: + - web diff --git a/lib/config.rb b/lib/config.rb index 6034d7e..ae516ce 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -1,7 +1,7 @@ module Config MORPHLIB = ENV.fetch('MORPHLIB') { '/morpheus/stemlib' } EXECUTABLE = ENV.fetch('EXECUTABLE') { '/morpheus/bin/morpheus' } - PORT = ENV.fetch('PORT') { '1316' } + PORT = ENV.fetch('PORT') { '1500' } EXPIRY = ENV.fetch('EXPIRY') { '604800' } REDIS_ENABLED = ENV.fetch('REDIS_ENABLED') { 'false' } REDIS_URL = ENV.fetch('REDIS_URL') { 'redis://127.0.0.1:6379/0' } diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..779d76b --- /dev/null +++ b/nginx.conf @@ -0,0 +1,24 @@ +events { } + +http { + proxy_cache_path /opt/cache/ keys_zone=cache:10m max_size=10g inactive=12h; + + server { + listen 1501; + listen [::]:1501; + + server_name localhost; + + location / { + proxy_cache cache; + proxy_cache_key $scheme$proxy_host$request_uri$http_accept; + proxy_cache_min_uses 2; + proxy_cache_valid any 7d; + + add_header Access-Control-Allow-Origin *; + add_header Access-Control-Allow-Methods 'GET'; + + proxy_pass http://web:1500/; + } + } +}