Skip to content

Instantly share code, notes, and snippets.

@chrisjensen
Last active January 21, 2021 02:42
Show Gist options
  • Save chrisjensen/cb563d9b267258676909dcd139890a9b to your computer and use it in GitHub Desktop.
Save chrisjensen/cb563d9b267258676909dcd139890a9b to your computer and use it in GitHub Desktop.
NGINX and Node NGINX.conf
# NGINX reverse proxies everything that comes to edge and either
# sends it to the edge Node server or to our API
#
# Some common problems you might encounter:
# SSL_do_handshake() failed (SSL: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure) while SSL handshaking to upstream
# Could mean you're passing a request to the API without using
# proxy_ssl_server_name on;
#
# If you're getting host not found issues you may need to
# proxy_set_header Host ${API_HOST}
http {
resolver $RESOLVER ipv6=off;
reset_timedout_connection on;
keepalive_timeout 650;
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:10m
inactive=10m max_size=1g;
server {
listen 8080 default_server;
location = /404.html {
internal;
root /home/app/api/assets/html/errors;
}
# Fast fail common errors
location = /favicon.ico {
return 404;
}
location / {
set $upstream http://127.0.0.1:8081;
set $px_cache STATIC;
set $px_host $host;
add_header X-Raisely-Cache-Status $upstream_cache_status;
# Note: We use the header forwarded by fly instead of $scheme
# because fly terminates SSL, so nginx always gets http requests
# (and no https requests)
proxy_cache_key $http_x_forwarded_proto$host$request_uri;
proxy_cache_valid 200 1m;
proxy_cache_lock on;
proxy_cache_background_update on;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_intercept_errors on;
proxy_ssl_server_name on;
# Configured by the if block
proxy_pass $upstream;
proxy_cache $px_cache;
# Forward the correct hostname to the recipient
proxy_set_header Host $px_host;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment