Skip to content

Instantly share code, notes, and snippets.

@HersonHN
Created April 11, 2020 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HersonHN/094cb697da254d47bfb0bd8810929ae4 to your computer and use it in GitHub Desktop.
Save HersonHN/094cb697da254d47bfb0bd8810929ae4 to your computer and use it in GitHub Desktop.
nginx configuration
events {
worker_connections 1024; # increase if you have lots of clients
accept_mutex on; # "on" if nginx worker_processes > 1
use epoll; # enable for Linux 2.6+
}
http {
map $sent_http_content_type $cacheable_types {
"text/css" "60d";
"text/html" "60d";
"application/javascript" "60d";
"image/jpeg" "150d";
"image/jpg" "150d";
"image/gif" "150d";
"image/png" "150d";
"application/x-font-woff" "1000d";
default "";
}
proxy_cache_path /proxy-cache levels=1:2 keys_zone=one:10m max_size=3000m inactive=600m;
proxy_temp_path /proxy-temp;
include /etc/nginx/mime.types;
default_type application/octet-stream;
keepalive_timeout 20;
reset_timedout_connection on;
client_body_timeout 5m;
client_header_timeout 5m;
send_timeout 5m;
limit_req_zone $binary_remote_addr zone=limitbyrps:10m rate=10r/s;
limit_req zone=limitbyrps burst=50;
types_hash_max_size 2048;
server_tokens off;
sendfile on;
tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
tcp_nodelay off; # on may be better for some Comet/long-poll stuff
gzip on;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 500;
gzip_types
application/json
application/javascript
application/x-javascript
application/xml
application/xml+rss
application/atom+xml
application/pdf
text/comma-separated-values
text/css
text/javascript
text/plain
text/html
text/xml
;
access_log /var/log/nginx/access.log;
charset utf-8;
upstream app {
server unix:/www/etc/etc/etc/socket.sock fail_timeout=0;
}
server {
listen 80 default;
listen 443 ssl;
server_name
www.example.com
example.com
api.example.com
;
root /www;
# host error and access log
access_log /var/log/nginx/myapp.access.log;
error_log /var/log/nginx/myapp.error.log;
client_max_body_size 4G;
keepalive_timeout 20;
proxy_connect_timeout 86400s;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1d;
client_body_buffer_size 1K;
client_header_buffer_size 8k;
large_client_header_buffers 4 32k;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_cache one;
proxy_cache_key sfs$request_uri$scheme;
proxy_redirect off;
proxy_pass http://app;
add_header 'Allow' 'GET, POST, DELETE, HEAD, OPTION, PATCH, FETCH, PUT';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS, PUT';
return 200;
}
}
error_page 500 502 504 /500.html;
error_page 503 @maintenance;
location = /500.html {
root /www/MYPROJECT/static/;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment