|
# https://gist.github.com/south37/d4a5a8158f49e067237c17d13ecab12a |
|
worker_processes 2; # or equal cpu core |
|
|
|
worker_rlimit_nofile 65535; # must change os nofile before |
|
events { |
|
worker_connections 8192; # must change os nofile before |
|
accept_mutex_delay 100ms; |
|
multi_accept on; |
|
use epoll; |
|
} |
|
|
|
http { |
|
include /etc/nginx/mime.types; |
|
|
|
proxy_cache_path /dev/shm/proxy_cache keys_zone=zone1:1m max_size=1g inactive=2m; |
|
proxy_temp_path /dev/shm/nginx_tmp; |
|
sendfile on; |
|
tcp_nopush on; |
|
tcp_nodelay on; |
|
open_file_cache max=2000 inactive=240s; |
|
|
|
log_format ltsv "time:$time_local" |
|
"\thost:$remote_addr" |
|
"\tforwardedfor:$http_x_forwarded_for" |
|
"\treq:$request" |
|
"\tstatus:$status" |
|
"\tmethod:$request_method" |
|
"\turi:$request_uri" |
|
"\tsize:$body_bytes_sent" |
|
"\treferer:$http_referer" |
|
"\tua:$http_user_agent" |
|
"\treqtime:$request_time" |
|
"\tcache:$upstream_http_x_cache" |
|
"\truntime:$upstream_http_x_runtime" |
|
"\tapptime:$upstream_response_time" |
|
"\tvhost:$host"; |
|
|
|
access_log /var/log/nginx/access.log ltsv; |
|
#access_log off; |
|
|
|
# client_body_temp_path /dev/shm/client_body_temp 1 2; |
|
# keepalive_requests 10000; # increase if needed |
|
|
|
gzip on; |
|
gzip_http_version 1.1; |
|
gzip_min_length 1000; |
|
gzip_types text/css |
|
application/font-tff |
|
application/font-woff |
|
application/javascript |
|
application/json |
|
application/octet-stream |
|
application/vnd.ms-fontobject |
|
application/x-www-form-urlencoded |
|
image/gif |
|
image/jpeg |
|
image/png |
|
image/svg+xml |
|
image/vnd.microsoft.icon; |
|
|
|
upstream local_app { |
|
server 127.0.0.1:1323 max_fails=0 fail_timeout=0; |
|
keepalive 30; |
|
} |
|
|
|
server { |
|
# static file の配信用の root |
|
root /home/isucon/webapp/public/; # change with specific app |
|
|
|
# add http1.1 version to location |
|
location /initialize { |
|
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_http_version 1.1; |
|
proxy_pass http://local_app; |
|
} |
|
|
|
location /api { |
|
proxy_http_version 1.1; |
|
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_pass http://local_app; |
|
} |
|
|
|
location /api/cached_endpoint { |
|
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_buffering on; |
|
proxy_cache zone1; |
|
proxy_cache_valid 200 302 60s; |
|
proxy_cache_key $scheme$proxy_host$uri$is_args$args; |
|
add_header X-Nginx-Cache $upstream_cache_status; |
|
|
|
proxy_pass http://local_app/api/cached_endpoint; |
|
} |
|
|
|
|
|
location ~* \.(png|ico|gif|jpg|jpeg|css|js|svg)$ { |
|
expires 7d; |
|
add_header Cache-Control "public"; |
|
} |
|
|
|
#location ~ .*\.(htm|html|css|js|jpg|png|gif|ico) { |
|
# expires 24h; |
|
# add_header Cache-Control public; |
|
# open_file_cache max=100; # file descriptor などを cache |
|
# gzip on; # cpu 使うのでメリット・デメリット見極める必要あり。gzip_static 使えるなら事前にgzip圧縮した上でそちらを使う。 |
|
# gzip_types text/css application/javascript application/json application/font-woff application/font-tff image/gif image/png image/jpeg image/svg+xml image/x-icon application/octet-stream; |
|
# gzip_disable "msie6"; |
|
# gzip_static on; # nginx configure時に --with-http_gzip_static_module 必要 |
|
# gzip_vary on; |
|
#} |
|
} |
|
|
|
} |