Skip to content

Instantly share code, notes, and snippets.

@AlexTiTanium
Last active November 12, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexTiTanium/c2fec5b6a1fda34755b1 to your computer and use it in GitHub Desktop.
Save AlexTiTanium/c2fec5b6a1fda34755b1 to your computer and use it in GitHub Desktop.
Nginx cache server
proxy_cache_path /tmp/nginx levels=1:2 keys_zone=local_cache:5m max_size=1g inactive=10m;
upstream api_buongiorno24 {
server 127.0.0.1:5000;
}
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
# Make site accessible from http://localhost/
server_name buongiorno24.local;
# Cache user specific requests
set $cache_key "$host$request_uri";
if ($request_uri ~* "^/api/user"){
set $cache_key "$host$request_uri$cookie_sid";
}
if ($request_uri ~* "^/api/sessions"){
set $cache_key "$host$request_uri$cookie_sid";
}
location /docs {
root /home/buongiorno/buongiorno24-api/;
index index.html;
}
location /api {
rewrite ^/api/(.*)$ /$1 break;
# Send all requests to upstream
try_files $uri @api;
}
location / {
root /home/buongiorno/buongiorno24-frontend/dist;
try_files $uri $uri/ /index.html;
}
# pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
location @api {
# Cache
proxy_cache_key "$cache_key";
proxy_cache local_cache;
#proxy_cache_lock on; # Good thing but on AB load works not well
proxy_cache_min_uses 3;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_valid 200 302 1m;
proxy_cache_methods GET HEAD;
proxy_cache_bypass $http_cache_control;
add_header X-Cache-Status $upstream_cache_status;
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_set_header X-NginX-Proxy true;
proxy_pass http://api_buongiorno24;
proxy_redirect off;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment