Skip to content

Instantly share code, notes, and snippets.

@ThienTranDuy
Created September 21, 2020 04:37
Show Gist options
  • Save ThienTranDuy/f40bdd162fad5fe1c87e982255b28f4a to your computer and use it in GitHub Desktop.
Save ThienTranDuy/f40bdd162fad5fe1c87e982255b28f4a to your computer and use it in GitHub Desktop.
Nginx config
server {
listen 80;
server_name main_domain.com www.main_domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl default_server;
# access_log off;
access_log /home/main_domain.com/logs/access.log;
# error_log off;
error_log /home/main_domain.com/logs/error.log;
root /var/www/main_domain.com/public_html;
index index.js index.html index.htm;
server_name main_domain.com www.main_domain.com;
# SSL
ssl_certificate /etc/letsencrypt/live/main_domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/main_domain.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
# Improve HTTPS performance with session resumption
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1d;
# DH parameters
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
# Enable HSTS
add_header Strict-Transport-Security "max-age=31536000" always;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header X-Real-IP $remote_addr; # This line.
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_connect_timeout 1000;
proxy_send_timeout 1500;
proxy_read_timeout 2000;
try_files $uri $uri/ index.html;
}
}
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
include /etc/nginx/proxy.conf;
include /etc/nginx/fastcgi.conf;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
log_format download '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$http_range" "$sent_http_content_range"';
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types application/javascript application/rss+xml application/vnd.ms-fontobject application/x-font application/x-font-opentype application/x-font-otf application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/opentype font/otf font/ttf image/svg+xml image/x-icon text/css text/javascript text/plain text/xml;
output_buffers 1 32k;
postpone_output 1460;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 75 20;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
include /etc/nginx/conf.d/*.conf;
}
server {
listen 443 ssl;
server_name other_domain.com www.other_domain.com;
# access_log off;
access_log /home/other_domain.com/logs/access.log;
# error_log off;
error_log /home/other_domain.com/logs/error.log;
# SSL
ssl_certificate /etc/letsencrypt/live/other_domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/other_domain.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
# Improve HTTPS performance with session resumption
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1d;
# DH parameters
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
# Enable HSTS
add_header Strict-Transport-Security "max-age=31536000" always;
location /
{
proxy_pass http://localhost:[PORT];
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header X-Real-IP $remote_addr; # This line.
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_connect_timeout 1000;
proxy_send_timeout 1500;
proxy_read_timeout 2000;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment