2
我有獨角獸和nginx在它前面的Rails應用程序。Nginx自定義error_page 413
# 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;
}
}
當413錯誤是由nginx
提出的,我希望把它傳遞給/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"
你有沒有得到這樣的情況?我也無法讓nginx顯示來自rails的50x錯誤的錯誤頁面。看起來像proxy_intercept_errors是要走的路,儘管它似乎也不工作。 – Kevin