carlessanagustin
3/9/2015 - 9:05 AM

Nginx app frontend / Load balancer / Static assets caching (not tested)

Nginx app frontend / Load balancer / Static assets caching (not tested)

# Number of worker processes. Set it to the number of available CPU cores as a good start value or use 'auto' to autodetect it
worker_processes 4;

# User and group used by worker processes
user www-data www-data;

# Skip superfluous info in the main error log file
error_log /var/log/nginx/error_log error;

# Limit number of files a worker process can open
worker_rlimit_nofile 1024;

pid /var/run/nginx.pid ;

events {
  worker_connections 1024;
}

http {
  server_names_hash_bucket_size 64;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  
  access_log /var/log/nginx/access.log;
  
  sendfile on;
  #tcp_nopush on;
  
  #keepalive_timeout 0;
  keepalive_timeout 65;
  tcp_nodelay on;
  
  gzip on;
  gzip_http_version 1.1;
  gzip_vary on;
  gzip_comp_level 6;
  gzip_proxied any;
  gzip_types text/plain text/css application/json application/x-javascript text/xml   application/xml application/xml+rss text/javascript;  
  gzip_buffers 16 8k; 
  
  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

# Nginx app frontend + Load balancer 
upstream projectname {
  server 22.22.22.2:3000;
  server 22.22.22.3:3000;
  server 22.22.22.5:3000;
}
 
server {
  listen 80;
  charset utf-8;

  server_name your-site.com www.your-site.com;
 
  location / {
    proxy_pass http://projectname;
  }
  # Static assets caching
  location ~* \.(css|js|gif|jpe?g|png)$ {
    expires 168h;
    
  }
  # Static assets caching
  location /api {
    expires 10m;
  }
}

# more https://gist.github.com/learncodeacademy/ebba574fc3f438c851ae
# more https://github.com/Stolz/linux-cheat-sheets/blob/master/nginx.md