V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
dommyet
V2EX  ›  问与答

Nginx 双向证书验证失败的页面有无办法美化一下?

  •  1
     
  •   dommyet · Feb 6, 2016 · 3500 views
    This topic created in 3739 days ago, the information mentioned may be changed or developed.

    如果 Nginx 端强制要求客户端提交证书的话,一旦因为客户端原因验证失败, Nginx 就会返回其丑无比的一个页面。

    仅当ssl_verify_client optional的时候可以使用$ssl_client_verify进行判断然后跳转到好看的页面,此时 Nginx 不强制要求客户端提交证书,于是在要求只能用证书登录的场合就只能用ssl_verify_client on

    然而ssl_verify_client on的时候上面那个判断跳转逻辑就不能用了,于是还是返回其丑无比的页面。

    请问如何破?详细情况麻烦移步看看我这篇文章

    Supplement 1  ·  Feb 7, 2016

    感谢 @orzfly 的解答 此问题已破

    server 段加入error_page 495 496 497 https://www.google.com;即可
    后面的ssl_client_verify判断不需要了

    http://nginx.org/en/docs/http/ngx_http_ssl_module.html#errors

    10 replies    2016-02-08 01:13:18 +08:00
    virusdefender
        1
    virusdefender  
       Feb 6, 2016
    自定义 400 页面模板试试呢
    Citrus
        2
    Citrus  
       Feb 6, 2016 via iPhone
    用 optional 然后后端验证是唯一的方法,否则 SSL 握手阶段根本就没完成,也就不存在返回错误页面之类的问题。
    dommyet
        3
    dommyet  
    OP
       Feb 6, 2016
    @virusdefender 你是说 error_page 400 xxx.html 这样吗 一开始就试过的了 不行的
    @Citrus 可以返回一个别的网页比如 return 303 https://www.google.com 这样 试过了是可以的 但是说到验证的问题好像后端验证确实是目前唯一可行的办法
    cevincheung
        4
    cevincheung  
       Feb 6, 2016
    如果为 optional ,

    在 /login 不用双向验证
    在 /trust-login 强制双向验证。
    怎么搞?
    shyling
        5
    shyling  
       Feb 7, 2016 via iPad
    在你的 if 里面使用
    try_files 你的不丑的页面的路径 =400;
    Citrus
        6
    Citrus  
       Feb 7, 2016 via iPhone
    @dommyet 你在 ssl_verify_client on 的时候可以 302 ?不可能吧。
    orzfly
        7
    orzfly  
       Feb 7, 2016   ❤️ 1
    http://nginx.org/en/docs/http/ngx_http_ssl_module.html#errors

    495 an error has occurred during the client certificate verification;
    496 a client has not presented the required certificate;
    497 a regular request has been sent to the HTTPS port.

    定义这几个错误代号的错误页吧。
    dommyet
        8
    dommyet  
    OP
       Feb 7, 2016
    @Citrus return 303 是可以的 https://forum.nginx.org/read.php?11,240460,240460 我也测试过是 ok 的 但是只能是 optional 并不强制要求提交证书 所以对我来说没什么用
    dommyet
        9
    dommyet  
    OP
       Feb 7, 2016
    @orzfly 正解 此问题已破 server 定义 error_page 495 496 497 https://www.google.com 即可 感谢
    Citrus
        10
    Citrus  
       Feb 8, 2016 via iPhone
    @dommyet 。。。我的前提就是开它 on 啊亲。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2532 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 15:01 · PVG 23:01 · LAX 08:01 · JFK 11:01
    ♥ Do have faith in what you're doing.