Skip to content

Instantly share code, notes, and snippets.

@brentkirby
Last active December 24, 2015 08:58
Show Gist options
  • Save brentkirby/6773632 to your computer and use it in GitHub Desktop.
Save brentkirby/6773632 to your computer and use it in GitHub Desktop.
Master nginx confs.
#-----------------------------------------------------------
# If using a proxy server
upstream app{
#server unix:///app_path/shared/sockets/app.sock fail_timeout=0;
server unix:///app_path/shared/sockets/app.sock;
}
#------------------------------------------------------------
server {
listen 80 default;
server_name example.com www.example.com;
set $app_root /apps/app_name
# Set to document root
root $app_root/current/public;
index index.html index.htm;
keepalive_timeout 5;
access_log $app_root/shared/log/nginx_access.log;
error_log $app_root/shared/log/nginx_error.log;
rewrite_log on;
error_page 502 503 /502.html;
error_page 500 /500.html;
error_page 404 /404.html;
location ~* \.(ico|css|js|gif|jpe?g|png|svg)(\?[0-9]+)?$ {
expires max;
break;
}
# 200mb upload max
client_max_body_size 200M;
# Rewrite non www
if ($host ~* www\.(.*)) {
set $host_without_www $1;
rewrite ^(.*)$ https://$host_without_www$1 permanent;
}
# Show a maintenance page if one exists.
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html break;
}
try_files $uri $uri/index.html @backend;
location @backend {
proxy_pass http://app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
}
user www-data;
worker_processes 8;
worker_rlimit_nofile 30000;
timer_resolution 500ms;
pid /run/nginx.pid;
events {
use epoll;
worker_connections 30000;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
# changes below
tcp_nodelay off;
# added
client_body_timeout 10;
client_header_timeout 10;
client_header_buffer_size 128;
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
proxy_buffer_size 32k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 32k;
proxy_temp_file_write_size 32k;
# end changes
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
# server_names_hash_bucket_size 64;
server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip changes
gzip_http_version 1.0;
gzip_buffers 4 16k;
gzip_comp_level 2;
gzip_min_length 0;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_proxied expired no-cache no-store private auth;
# end changes
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment