Skip to content

Instantly share code, notes, and snippets.

@mattimatti
Last active June 25, 2018 13:30
Show Gist options
  • Save mattimatti/b2e77e35facee491786c67e0944ee0d4 to your computer and use it in GitHub Desktop.
Save mattimatti/b2e77e35facee491786c67e0944ee0d4 to your computer and use it in GitHub Desktop.
nginx.conf to proxy pass google storage engine bucket with https support
events {
}
http {
# Proxy Cache
# Cache 10GB for 1 Month
#proxy_cache_path /var/cache/nginx keys_zone=GS:10m inactive=720h max_size=10240m;
log_format upstreamlog '[$time_local] $remote_addr - $remote_user - $server_name to: $upstream_addr: $request upstream_response_time $upstream_response_time msec $msec request_time $request_time';
access_log /var/log/nginx/access.log upstreamlog;
upstream gs {
server 'storage.googleapis.com:80';
keepalive 100;
}
server {
server_name {{ domain }};
listen 80;
listen [::]:80;
return 301 https://{{ domain }}$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name {{ domain }};
ssl_certificate /etc/letsencrypt/live/{{ domain }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ domain }}/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/{{ domain }}/fullchain.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_dhparam /etc/nginx/certs/dhparam.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
# Logs
#access_log /var/log/nginx/{{ domain }}.access.log main;
access_log off;
error_log /var/log/nginx/{{ domain }}.error.log debug;
# Cache Control
expires max;
add_header Cache-Control "public, max-age=31536000";
# Nameserver
resolver 8.8.8.8 valid=300s;
resolver_timeout 10s;
# https://stackoverflow.com/questions/40274669/nginx-proxy-pass-content-range
#postpone_output 0;
proxy_pass_request_headers on;
send_timeout 100m;
#proxy_temp_path /tmp/nginx;
#proxy_cache_lock on;
#proxy_cache_key "$uri"; # Ignore Parameters
# https://github.com/FRiCKLE/ngx_cache_purge
#proxy_cache_purge on from 127.0.0.1;
# Limit Request Methods to GET|HEAD|PURGE
if ( $request_method !~ "GET|HEAD|PURGE" ) {
return 405;
}
#gzip on;
#server_tokens off;
location / {
#rewrite ^/app/hit/(.*)$ /hit_page.php?path=$1 break;
rewrite ^/$ /index.html;
proxy_set_header Host storage.googleapis.com;
proxy_hide_header x-goog-hash;
proxy_hide_header x-goog-generation;
proxy_hide_header x-goog-metageneration;
proxy_hide_header x-goog-stored-content-encoding;
proxy_hide_header x-goog-stored-content-length;
proxy_hide_header x-goog-storage-class;
proxy_hide_header x-xss-protection;
# Removes the ranges preventing videos to work..
#proxy_hide_header accept-ranges;
proxy_hide_header alternate-protocol;
proxy_hide_header Set-Cookie;
proxy_ignore_headers "Set-Cookie";
proxy_intercept_errors on;
#proxy_cache GS;
#proxy_cache_valid 200 720h; # Cache For 1 Month
#proxy_cache_bypass $http_cache_purge;
#add_header X-Cache $upstream_cache_status;
proxy_http_version 1.1;
#proxy_set_header Connection "";
proxy_pass http://gs/{{ bucket_name }}$uri;
}
# TODO: handle proxy errors
}
server {
server_name www.{{ domain }};
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
return 301 https://www.{{ domain }}$request_uri;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment