Created
June 28, 2015 01:41
-
-
Save daimagine/606928e0f9ac88afb037 to your computer and use it in GitHub Desktop.
Nginx Configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user www; | |
worker_processes 1; | |
error_log /var/log/nginx/error.log; | |
pid /usr/local/etc/nginx/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
# Enumerate all the Tornado servers here | |
upstream frontends { | |
server 127.0.0.1:8000; | |
} | |
include /usr/local/etc/nginx/mime.types; | |
default_type application/octet-stream; | |
log_format log_req_resp '$remote_addr - $remote_user [$time_local] ' | |
'"$request" $status $body_bytes_sent ' | |
'"$http_referer" "$http_user_agent" $request_time req_body:"$request_body" resp_body:"$resp_body"'; | |
access_log /var/log/nginx/access.log log_req_resp; | |
lua_need_request_body on; | |
set $resp_body ""; | |
body_filter_by_lua ' | |
local resp_body = string.sub(ngx.arg[1], 1, 1000) | |
ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body | |
if ngx.arg[2] then | |
ngx.var.resp_body = ngx.ctx.buffered | |
end | |
'; | |
keepalive_timeout 65; | |
proxy_read_timeout 200; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
gzip on; | |
gzip_min_length 1000; | |
gzip_proxied any; | |
gzip_types text/plain text/html text/css text/xml | |
application/x-javascript application/xml | |
application/atom+xml text/javascript; | |
# Only retry if there was a communication error, not a timeout | |
# on the Tornado server (to avoid propagating "queries of death" | |
# to all frontends) | |
proxy_next_upstream error; | |
server { | |
listen 3000; | |
# Allow file uploads | |
client_max_body_size 50M; | |
location / { | |
proxy_pass_header Server; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Scheme $scheme; | |
proxy_pass http://frontends; | |
add_header X-Request-Time $request_time; | |
add_header X-Upstream-Server $upstream_http_server; | |
add_header X-Upstream-Status $upstream_status; | |
add_header X-Upstream-Addr $upstream_addr; | |
add_header X-Upstream-Time $upstream_response_time; | |
add_header X-Upstream-Cache $upstream_cache_status; | |
add_header X-Upstream-Content-Type $upstream_http_content_type; | |
add_header X-Upstream-Location $upstream_http_location; | |
add_header X-Upstream-Random-Junk $upstream_http_random_junk; | |
if ($request_method = 'OPTIONS') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
# | |
# Om nom nom cookies | |
# | |
add_header 'Access-Control-Allow-Credentials' 'true'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
# | |
# Custom headers and headers various browsers *should* be OK with but aren't | |
# | |
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
# | |
# Tell client that this pre-flight info is valid for 20 days | |
# | |
add_header 'Access-Control-Max-Age' 1728000; | |
add_header 'Content-Type' 'text/plain charset=UTF-8'; | |
add_header 'Content-Length' 0; | |
return 204; | |
} | |
if ($request_method = 'POST') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Credentials' 'true'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
} | |
if ($request_method = 'GET') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Credentials' 'true'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment