After configuring a Guomi (SM cryptography) certificate, Nginx fails to start with the error "SSL_CTX_use_certificate failed". How to resolve this?
Cause of the error
This occurs because the OpenSSL library underlying the current middleware does not support Guomi algorithms (SM2/SM3/SM4).
Standard OpenSSL cannot recognize the Guomi certificate format, which causes certificate loading to fail.
Solution
You need to compile and install a Guomi-enabled OpenSSL distribution (such as GmSSL, Tongsuo, and other OpenSSL forks that support Guomi algorithms), then recompile Nginx against this version to enable support for loading Guomi certificates.
Procedure (brief):
- Download and compile a Guomi-enabled OpenSSL distribution (Tongsuo is recommended)
- Recompile Nginx using the Guomi-enabled OpenSSL (
--with-openssl=...points to the Guomi-enabled version) - Configure dual certificates in Nginx (Guomi certificate + RSA certificate) to ensure compatibility across all scenarios