Last active
December 14, 2021 00:33
-
-
Save rauluranga/31281c616101a4349e54cc2421a2e159 to your computer and use it in GitHub Desktop.
NGINX HTTP/2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# command to generate dhparams.pen | |
# openssl dhparam -out /etc/nginx/conf.d/dhparams.pem 2048 | |
include /redirects.conf; | |
server { | |
listen 80; | |
listen [::]:80; | |
access_log off; | |
error_log off; | |
server_name www.your-domain.com; | |
return 301 https://www.your-domain.com$request_uri; | |
} | |
# from https://hstspreload.org/ fix | |
# you should have a :80 naked domain to redirect :443 naked domain | |
server { | |
listen 80; | |
listen [::]:80; | |
access_log off; | |
error_log off; | |
server_name your-domain.com; | |
return 301 https://your-domain.com$request_uri; | |
} | |
# from https://hstspreload.org/ fix | |
# you should preload a SSL naked domain instead of www subdomain | |
server { | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
access_log off; | |
error_log off; | |
server_name your-domain.com; | |
ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; # managed by Certbot | |
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; # managed by Certbot | |
include /etc/nginx/snippets/security-headers.conf; | |
return 301 https://www.your-domain.com$request_uri; | |
} | |
server { | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
server_name www.your-domain.com; | |
ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; # managed by Certbot | |
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; # managed by Certbot | |
# include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot | |
# ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot | |
# ---- START Configuration for improved security --- | |
# @see https://ssl-config.mozilla.org/ | |
ssl_session_cache shared:le_nginx_SSL:50m; | |
ssl_session_timeout 1d; | |
ssl_session_tickets off; | |
ssl_protocols TLSv1.2 TLSv1.3; | |
ssl_prefer_server_ciphers on; | |
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; | |
ssl_dhparam /etc/nginx/ssl/dhparam.pem; | |
ssl_ecdh_curve secp384r1; | |
# OCSP stapling | |
ssl_stapling on; | |
ssl_stapling_verify on; | |
ssl_trusted_certificate /etc/letsencrypt/live/your-domain.com/chain.pem; | |
resolver 8.8.8.8 8.8.4.4 valid=300s; | |
resolver_timeout 5s; | |
include /etc/nginx/snippets/security-headers.conf; | |
# ---- END Configuration for improved security --- | |
root /var/www/your_domain_com; | |
index index.php index.html index.htm index.nginx-debian.html; | |
access_log /var/log/nginx/your-domain.com.access.log; | |
error_log /var/log/nginx/your-domain.com.error.log; | |
if ( $redirect_uri ) { | |
return 301 $redirect_uri; | |
} | |
error_page 404 /404.html; | |
location / { | |
try_files $uri $uri/ =404; | |
} | |
location ~ \.php$ { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; | |
} | |
# Browser Caching https://gist.github.com/philipstanislaus/654adafad91efb6de230845b5bdeae61 | |
location ~* \.(?:css|js|html)$ { | |
access_log off; | |
log_not_found off; | |
expires 7d; | |
add_header Cache-Control "public, no-transform"; | |
include /etc/nginx/snippets/security-headers.conf; | |
} | |
location ~* \.(?:jpg|jpeg|gif|png|ico|xml|pdf|ppt|pptx|doc|docx|txt|bmp|rtf|svg)$ { | |
access_log off; | |
log_not_found off; | |
expires 30d; | |
add_header Cache-Control "public"; | |
include /etc/nginx/snippets/security-headers.conf; | |
} | |
location ~* \.(?:eot|woff|woff2|ttf|otf) { | |
access_log off; | |
log_not_found off; | |
expires 30d; | |
add_header Cache-Control "public"; | |
add_header Access-Control-Allow-Origin *; | |
include /etc/nginx/snippets/security-headers.conf; | |
types {font/opentype otf;} | |
types {application/vnd.ms-fontobject eot;} | |
types {font/truetype ttf;} | |
types {application/font-woff woff;} | |
types {font/x-woff woff2;} | |
} | |
location ~ /\. { | |
access_log off; | |
log_not_found off; | |
deny all; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map $request_uri $redirect_uri { | |
/old_uri /new_uri; | |
/old_uri_v2 /new_uri_v2; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Strict Transport Security Header | |
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; | |
add_header X-Frame-Options DENY; | |
add_header X-Content-Type-Options nosniff; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment