我在unicorn和nginx前面有rails应用程序。
# nginx.conf
upstream backend {
server unix:/home/deployer/apps/example.ru/shared/tmp/sockets/unicorn.sock.0 fail_timeout=0;
server unix:/home/deployer/apps/example.ru/shared/tmp/sockets/unicorn.sock.1 fail_timeout=0;
}
log_format default_log '$host $remote_addr [$time_local] "$request" $status $request_length "$http_referer" "$http_user_agent" $request_time';
server {
listen 80;
server_name example.ru www.example.ru dev.example.ru;
access_log /var/log/nginx/example.ru-access.log default_log;
# recursive_error_pages on;
location ~ ^/assets/ {
root /home/deployer/apps/example.ru/current/public;
gzip_static on;
expires 1y;
add_header Cache-Control public;
add_header ETag "";
break;
}
location / {
auth_basic "You shall not pass!";
auth_basic_user_file /home/deployer/.htsandbox;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_pass http://backend;
proxy_redirect off;
}
# Error pages
error_page 413 /413;
if (-f /home/deployer/apps/example.ru/shared/public/system/maintenance.html) {
return 503;
}
error_page 503 @maintenance;
location @maintenance {
if (-f $request_filename) {
break;
}
root /home/deployer/apps/example.ru/shared/public/system;
rewrite ^(.*)$ /maintenance.html break;
}
error_page 502 @bad_gateway;
location @bad_gateway {
if (-f $request_filename) {
break;
}
root /home/deployer/apps/example.ru/shared/public/system;
rewrite ^(.*)$ /bad_gateway.html break;
}
}
当nginx
引发413错误时,我想将其传递给独角兽错误页面/413
。但是有502 Bad Gateway
nginx错误页面。
#log
2013/12/12 12:56:10 [error] 16853#0: *55 client intended to send too large body: 4099547 bytes, client: 128.72.7.207, server: example.ru, request: "POST /users/tester/avatar HTTP/1.1", host: "dev.example.ru", referrer: "http://dev.example.ru/users/tester/avatar"
2013/12/12 12:56:41 [error] 16853#0: *55 upstream prematurely closed connection while reading response header from upstream, client: 128.72.7.207, server: example.ru, request: "POST /users/tester/avatar HTTP/1.1", upstream: "http://unix:/home/deployer/apps/example.ru/shared/tmp/sockets/unicorn.sock.0:/413", host: "dev.example.ru", referrer: "http://dev.example.ru/users/tester/avatar"
2013/12/12 12:57:12 [error] 16853#0: *55 upstream prematurely closed connection while reading response header from upstream, client: 128.72.7.207, server: example.ru, request: "POST /users/tester/avatar HTTP/1.1", upstream: "http://unix:/home/deployer/apps/example.ru/shared/tmp/sockets/unicorn.sock.1:/413", host: "dev.example.ru", referrer: "http://dev.example.ru/users/tester/avatar"