Skip to content

Instantly share code, notes, and snippets.

@tzkmx
Created October 9, 2017 20:16
Show Gist options
  • Save tzkmx/6f6f909fac7682f04fbcc060a19ccdb5 to your computer and use it in GitHub Desktop.
Save tzkmx/6f6f909fac7682f04fbcc060a19ccdb5 to your computer and use it in GitHub Desktop.
Proxy and cache POST request queries to remote GraphQL server
upstream my_graphql_server {
server launchpad.example.host:443 ;
}
server {
listen 192.168.1.20:443 ssl http2;
server_name myserverhost.lan;
ssl_certificate /usr/local/certificates/cert-wCa2Ie;
ssl_certificate_key /usr/local/certificates/cert-wCa2Ie;
ssl_client_certificate /usr/local/certificates/cert-eJPfDa;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
client_max_body_size 2m;
root "/var/www/vhosts/myserverhost.lan/public";
access_log "/var/www/vhosts/myserverhost.lan/logs/proxy_access_ssl_log";
error_log "/var/www/vhosts/myserverhost.lan/logs/proxy_error_log";
location @graphql {
proxy_pass https://my_graphql_server/graphql;
proxy_http_version 1.1;
proxy_cache GRAPHQLDEV;
proxy_cache_methods POST;
proxy_buffers 8 32k;
proxy_buffer_size 64k;
add_header X-Cached $upstream_cache_status;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host 'launchpad.example.host';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
try_files $uri $uri/ @graphql;
}
}
proxy_cache_path /var/run/graphqldev-cache levels=2:2 keys_zone=GRAPHQLDEV:1m inactive=1m;
proxy_cache_valid 200 301 302 60s;
proxy_cache_key "$request_uri|$request_body";
proxy_cache_use_stale error timeout invalid_header updating http_500;
proxy_cache_lock on;
proxy_cache_lock_age 5s;
proxy_cache_lock_timeout 8s;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment