如何禁用SSL证书并且仅用于在Nginx中的端口443上转发流量?

时间:2018-08-27 14:34:14

标签: ssl nginx https iptables nginx-config

主机A具有https服务 serviceA ,并提供两个IP以实现高可用性。

  

例如Bose [ip1:443]和[ip2:443]被路由到 serviceA

主机B(没有ssl_certificate和ssl_certificate_key)使用Nginx代理模块将请求代理到实际的 serviceA 。 如何在没有SSL验证的情况下简单地将443端口流量转发到 serviceA ? 这是我的配置:

http {
  upstream backend {
    server [ip1]:443;
    server [ip2]:443;
  }

  server {
    listen       443;
    listen       [::]:443;

    location / {
        proxy_pass  https://backend;
    }

  }
}

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:1)

尝试:

public class CertificateHelper {

    private static String CERTIFICATE_SHA1 = "HASH FROM KEYTOOL";

    private static String calcSHA1(byte[] signature) throws NoSuchAlgorithmException {
        MessageDigest digest = MessageDigest.getInstance("SHA1");
        digest.update(signature);
        byte[] signatureHash = digest.digest();
        return toHex(signatureHash);
    }

    public static boolean validateAppSignature(Context context) {

        try {
            // get the signature form the package manager
            String packageName = context.getPackageName();
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
            Signature[] appSignatures = packageInfo.signatures;
            // this sample only checks the first certificate
            for (Signature signature : appSignatures) {
                byte[] signatureBytes = signature.toByteArray();
                // calc sha1 in hex
                String currentSignature = calcSHA1(signatureBytes);
                // compare signatures
                if (CERTIFICATE_SHA1.equalsIgnoreCase(currentSignature)) {
                    return true;
                }
            }
        } catch (Exception e) { // if error assume failed to validate
            return false;
        }
        return false;
    }
}

它不起作用