首页 > 代码库 > nginx中error_page没有生效(nginx+passenger+rails)

nginx中error_page没有生效(nginx+passenger+rails)

应用部署方式为 nginx + passenger + rails 

当我想要用nginx来默认处理400以上状态时,发现在rails返回respose之后,nginx不会再次执行error_page(官方介绍该directive在proxy返回response依然会执行),原因在于需要配置 passenger_intercept_errors on ;

nginx.conf 中 server 配置:

    server {        listen 3443 ssl;        server_name XXX;        ssl_certificate /root/ssl/server.crt;        ssl_certificate_key /root/ssl/server.key;        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;        ssl_ciphers HIGH:!aNULL:!MD5;        root /var/ror/cas/public;        passenger_enabled on;        passenger_intercept_errors on;   #问题根源        passenger_ruby /usr/local/rvm/gems/ruby-2.3.0/wrappers/ruby;        access_log /var/ror/logs/access.log;        error_log /var/ror/logs/error.log debug;        # redirect server error pages to the static page /40x.html        error_page 404 /404.html;        location = /404.html {        }        error_page 403 = /403.html;        location = /403.html {        }        # redirect server error pages to the static page /50x.html        error_page   500 502 503 504  /50x.html;        location = /50x.html {        }    }        

参考: https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#passenger_intercept_errors

 

nginx中error_page没有生效(nginx+passenger+rails)