Skip to content

Instantly share code, notes, and snippets.

@YarikST
Created October 10, 2019 16:30
Show Gist options
  • Save YarikST/dc39dd7a9cb68eb890cf557764522c24 to your computer and use it in GitHub Desktop.
Save YarikST/dc39dd7a9cb68eb890cf557764522c24 to your computer and use it in GitHub Desktop.
#acme
location ^~/.well-known {
default_type "text/plain";
root /var/www/html;
}
events {
worker_connections 768; #10000 Load balancer
multi_accept on;
}
#Load balancer redirect http to https and http to www-version
server {
listen 80 default_server;
server_name prod.safepalapp.com;
return 301 https://www.prod.safepalapp.com$request_uri;
}
#Load balancer
server {
listen 80;
server_name www.prod.safepalapp.com;
root /var/www/safepal/public;
passenger_app_env production;
passenger_enabled on;
passenger_ruby /home/ubuntu/.rvm/gems/ruby-2.4.0@safepal/wrappers/ruby;
location /health {
return 200 "healthy\n";
}
include acme;
if ($http_x_forwarded_proto = 'http'){
return 301 https://www.prod.safepalapp.com$request_uri;
}
location ~ ^/(assets|fonts|images|javascripts|firebase-messaging-sw.js|manifest.json|robots.txt) {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location / {
proxy_intercept_errors on;
error_page 404 404.html;
error_page 422 422.html;
error_page 500 500.html;
}
location /socket {
client_max_body_size 10m;
passenger_app_group_name safepal_action_cable;
passenger_force_max_concurrent_requests_per_process 0;
}
}
#Singleton redirect http to https and http to www-version
server {
listen 80 default_server;
server_name safepal.tk www.safepal.tk;
return 301 https://www.safepal.tk$request_uri;
}
#Singleton redirect https to www-version
server {
ssl on;
listen 443 default_server;
server_name safepal.tk;
return 301 https://www.safepal.tk$request_uri;
}
#Singleton
server {
ssl on;
listen 443;
server_name www.safepal.tk;
root /var/www/safepal/public;
passenger_app_env production;
passenger_enabled on;
passenger_ruby /home/ubuntu/.rvm/gems/ruby-2.4.0@safepal/wrappers/ruby;
include acme;
location / {
proxy_intercept_errors on;
error_page 404 404.html;
error_page 422 422.html;
error_page 500 500.html;
}
location ~ ^/(assets|fonts|images|javascripts|firebase-messaging-sw.js|manifest.json|robots.txt) {
gzip_static on;
expires max;
add_header Cache-Control public;
}
}
#Singleton custom WebScoket
server {
ssl on;
listen 8433;
server_name www.safepal.tk;
root /var/www/safepal/public;
passenger_app_env production;
passenger_enabled on;
passenger_app_group_name safepal_action_cable;
passenger_app_type rack;
passenger_startup_file cable/config.ru;
passenger_force_max_concurrent_requests_per_process 0;
}
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65; #86400 Load balancer
keepalive_requests 100; #10000 Load balancer
client_header_timeout 10; #remove Load balancer
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 2;
types_hash_max_size 2048;
server_tokens off;
absolute_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_max_body_size 500m;
##
# Gzip Settings
##
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 8;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
##
# SSL Settings
##
ssl_protocols SSLv3 TLSv1;
ssl_certificate /etc/letsencrypt/live/safepal.tk/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/safepal.tk/privkey.pem;
# Improve HTTPS performance with session resumption
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
# Enable server-side protection against BEAST attacks
ssl_prefer_server_ciphers on;
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
# Disable SSLv3
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# Diffie-Hellman parameter for DHE ciphersuites
# $ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 4096
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
# Enable HSTS (https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security)
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
# Enable OCSP stapling (http://blog.mozilla.org/security/2013/07/29/ocsp-stapling-in-firefox)
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/letsencrypt/live/safepal.tk/fullchain.pem;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment