Skip to content

Instantly share code, notes, and snippets.

@baskaran-md
Last active December 17, 2017 06:57
Show Gist options
  • Save baskaran-md/21e1e63ddfd8211fb753 to your computer and use it in GitHub Desktop.
Save baskaran-md/21e1e63ddfd8211fb753 to your computer and use it in GitHub Desktop.
nginx.conf - 5xx,4xx
###
# THIS NGINX IS TUNED FOR PERFORMANCE
###
#user nobody;
worker_processes 8;
worker_rlimit_nofile 100000;
events {
worker_connections 4000;
# optmized to serve many clients with each thread, essential for linux
use epoll;
# accept as many connections as possible, may flood worker connections if set too low
multi_accept on;
}
error_log logs/error.log crit;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
# cache informations about FDs, frequently accessed files
# can boost performance, but you need to test those values
http {
include 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 logs/access.log main;
sendfile on;
tcp_nopush on;
# don't buffer data sent, good for small data bursts in real time
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 100000;
# allow the server to close connection on non responding client, this will free up memory
reset_timedout_connection on;
# request timed out -- default 60
client_body_timeout 10;
# if client stop responding, free up memory -- default 60
send_timeout 2;
# reduce the data that needs to be sent over network
gzip on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";
server {
listen 80;
server_name localhost#;
client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 2 1k;
client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 15;
send_timeout 10;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
#charset koi8-r;
access_log off;
location ~* .(jpg|jpeg|png|gif|ico|css|js|json|xml)$ {
expires 1d;
}
location / {
root html;
index index.html index.htm;
}
location /v1/data {
autoindex on;
autoindex_exact_size on;
}
location /d1 {
autoindex on;
autoindex_exact_size on;
}
error_page 404 /404.html;
error_page 403 /403.html;
error_page 405 =200 $uri;
error_page 500 =500 $uri;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
keepalive_timeout 60;
root html;
}
# This will send "Connection: close" header automatically.
# This is for response code 200
location = /2.0/services_200 {
keepalive_timeout 0;
}
# This will send "Connection: close" header automatically.
# This is for response code 500
location = /2.0/services {
return 500;
}
location = /2.0/services_300 {
return 302;
}
location = /2.0/services_100 {
return 101;
}
location = /2.0/services_401 {
return 401;
}
location = /2.0/services_400 {
return 400;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
# This is to introduce delay on a resource
location = /v2/delay.xml {
echo_sleep $arg_wait;
echo_location /v2/data/1k.xml;
}
location ^~ /api/ {
location ~* \.(json)$ {
more_clear_headers 'Content-Type';
more_clear_headers 'Transfer-Encoding';
add_header Content-Length 1024;
echo_location /v2/data/1k.json;
add_header Content-Type application/json;
}
location ~* \.(xml)$ {
more_clear_headers 'Content-Type';
more_clear_headers 'Transfer-Encoding';
add_header Content-Length 1024;
echo_location /v2/data/1k.xml;
add_header Content-Type application/xml;
}
more_clear_headers 'Content-Type';
more_clear_headers 'Transfer-Encoding';
add_header Content-Length 1024;
echo_location /v2/data/1k.txt;
add_header Content-Type text/plain;
}
}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment