Skip to content

Instantly share code, notes, and snippets.

@wilsontayar
Forked from rodolfofadino/nginx.conf
Last active August 29, 2015 14:06
Show Gist options
  • Save wilsontayar/4d33ad6f096ad788acf3 to your computer and use it in GitHub Desktop.
Save wilsontayar/4d33ad6f096ad788acf3 to your computer and use it in GitHub Desktop.
nginx.conf file optimized for nginx 1.7.4 with the pagespeed module installed
worker_processes 5;
worker_rlimit_nofile 300000;
pid /var/run/nginx.pid;
events {
worker_connections 10540;
# multi_accept on;
}
http {
proxy_cache_path /data/nginx/cachepath levels=1:2 keys_zone=STATIC:50m
inactive=12h max_size=5g;
## Proxy caching options
# proxy_buffering on;
proxy_cache_min_uses 1;
proxy_ignore_client_abort off;
proxy_intercept_errors on;
proxy_next_upstream error timeout invalid_header;
proxy_redirect off;
# proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
include mime.types;
default_type application/octet-stream;
access_log off;
# error_log /dev/null crit;
#error_log /etc/nginx/log/error.log;
gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_types text/plain text/xml text/html text/css application/x-javascript text/javascript application/json application/xml+rss;
gzip_vary on;
##
# Virtual Host Configs
##
# Size Limits
client_body_buffer_size 128K;
client_header_buffer_size 2M;
client_max_body_size 2M;
large_client_header_buffers 8 8k;
## Timeouts
client_body_timeout 60;
client_header_timeout 60;
expires 24h;
keepalive_timeout 60 60;
send_timeout 60;
## General Options
ignore_invalid_headers on;
keepalive_requests 100;
limit_zone gulag $binary_remote_addr 5m;
recursive_error_pages on;
sendfile on;
server_name_in_redirect off;
server_tokens off;
## TCP options
tcp_nodelay on;
tcp_nopush on;
pagespeed StatisticsPath /ngx_pagespeed_statistics;
pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics;
pagespeed MessagesPath /ngx_pagespeed_message;
pagespeed ConsolePath /pagespeed_console;
pagespeed AdminPath /pagespeed_admin;
pagespeed GlobalAdminPath /pagespeed_global_admin;
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen # [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www;
index index.html index.htm;
pagespeed on;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;
location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; }
location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }
location /pagespeed_console { allow 127.0.0.1; deny all; }
location ~ ^/pagespeed_admin { allow 127.0.0.1; deny all; }
location ~ ^/pagespeed_global_admin { allow 127.0.0.1; deny all; }
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
# Make site accessible from http://localhost/
server_name localhost;
location / {
proxy_pass http://origin.server.com;
proxy_set_header Host $host;
proxy_cache STATIC;
proxy_cache_valid ANY 1m;
proxy_cache_valid 302 5m;
proxy_cache_valid 200 5d;
proxy_cache_valid 404 1m;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
expires 72h;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment