Skip to content

Instantly share code, notes, and snippets.

@huangsam
Last active January 24, 2019 17:24
Show Gist options
  • Save huangsam/874b1bcd7153da2822e0338a13772581 to your computer and use it in GitHub Desktop.
Save huangsam/874b1bcd7153da2822e0338a13772581 to your computer and use it in GitHub Desktop.
Production-level Nginx configuration
resolver 8.8.8.8 8.8.4.4 valid=10s;
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;
server {
listen 80;
listen [::]:80;
server_name _;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name _;
root /usr/share/nginx/html;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /bogus/chain.pem
ssl_certificate /bogus/fullchain.pem
ssl_certificate_key /bogus/privkey.pem
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
location / {
limit_req zone=mylimit burst=20 nodelay;
index index.html index.htm;
}
location ~* \.(svg|jpg|jpeg|png|gif|ico|css|js|ttf)$ {
expires 30d;
}
error_page 404 /404.html;
location /404.html {
internal;
}
error_page 500 501 502 503 /50x.html;
location /50x.html {
internal;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
tcp_nopush on;
tcp_nodelay off;
gzip on;
gzip_static on;
gzip_vary on;
gzip_disable 'msie6';
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
text/plain
text/javascript
text/x-javascript
text/xml
text/css
application/javascript
application/x-javascript
application/json
application/xml
font/truetype
font/opentype
image/svg+xml;
include /etc/nginx/conf.d/*.conf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment