a6d5b6
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
a6d5b6
index 2b0c5e6..9278087 100644
a6d5b6
--- a/src/event/ngx_event_openssl.c
a6d5b6
+++ b/src/event/ngx_event_openssl.c
a6d5b6
@@ -258,6 +258,8 @@ ngx_ssl_init(ngx_log_t *log)
a6d5b6
 ngx_int_t
a6d5b6
 ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data)
a6d5b6
 {
a6d5b6
+    ngx_uint_t prot = NGX_SSL_NO_PROT;
a6d5b6
+
a6d5b6
     ssl->ctx = SSL_CTX_new(SSLv23_method());
a6d5b6
 
a6d5b6
     if (ssl->ctx == NULL) {
a6d5b6
@@ -322,49 +324,54 @@ ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data)
a6d5b6
 
a6d5b6
     SSL_CTX_set_options(ssl->ctx, SSL_OP_SINGLE_DH_USE);
a6d5b6
 
a6d5b6
-#if OPENSSL_VERSION_NUMBER >= 0x009080dfL
a6d5b6
-    /* only in 0.9.8m+ */
a6d5b6
-    SSL_CTX_clear_options(ssl->ctx,
a6d5b6
-                          SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
a6d5b6
-#endif
a6d5b6
-
a6d5b6
-    if (!(protocols & NGX_SSL_SSLv2)) {
a6d5b6
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_SSLv2);
a6d5b6
-    }
a6d5b6
-    if (!(protocols & NGX_SSL_SSLv3)) {
a6d5b6
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_SSLv3);
a6d5b6
-    }
a6d5b6
-    if (!(protocols & NGX_SSL_TLSv1)) {
a6d5b6
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1);
a6d5b6
-    }
a6d5b6
-#ifdef SSL_OP_NO_TLSv1_1
a6d5b6
-    SSL_CTX_clear_options(ssl->ctx, SSL_OP_NO_TLSv1_1);
a6d5b6
-    if (!(protocols & NGX_SSL_TLSv1_1)) {
a6d5b6
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1_1);
a6d5b6
-    }
a6d5b6
+    if (protocols){
a6d5b6
+#ifdef SSL_OP_NO_TLSv1_3
a6d5b6
+        if (protocols & NGX_SSL_TLSv1_3) {
a6d5b6
+            prot = TLS1_3_VERSION;
a6d5b6
+        } else
a6d5b6
 #endif
a6d5b6
 #ifdef SSL_OP_NO_TLSv1_2
a6d5b6
-    SSL_CTX_clear_options(ssl->ctx, SSL_OP_NO_TLSv1_2);
a6d5b6
-    if (!(protocols & NGX_SSL_TLSv1_2)) {
a6d5b6
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1_2);
a6d5b6
-    }
a6d5b6
+        if (protocols & NGX_SSL_TLSv1_2) {
a6d5b6
+            prot =  TLS1_2_VERSION;
a6d5b6
+        } else
a6d5b6
 #endif
a6d5b6
-#ifdef SSL_OP_NO_TLSv1_3
a6d5b6
-    SSL_CTX_clear_options(ssl->ctx, SSL_OP_NO_TLSv1_3);
a6d5b6
-    if (!(protocols & NGX_SSL_TLSv1_3)) {
a6d5b6
-        SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_TLSv1_3);
a6d5b6
-    }
a6d5b6
+#ifdef SSL_OP_NO_TLSv1_1
a6d5b6
+        if (protocols & NGX_SSL_TLSv1_1) {
a6d5b6
+            prot = TLS1_1_VERSION;
a6d5b6
+        } else
a6d5b6
 #endif
a6d5b6
+        if (protocols & NGX_SSL_TLSv1) {
a6d5b6
+            prot = TLS1_VERSION;
a6d5b6
+        }
a6d5b6
+
a6d5b6
+        if (prot == NGX_SSL_NO_PROT) {
a6d5b6
+                    ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
a6d5b6
+                      "No SSL protocols available [hint: ssl_protocols]");
a6d5b6
+            return NGX_ERROR;
a6d5b6
+        }
a6d5b6
 
a6d5b6
-#ifdef SSL_CTX_set_min_proto_version
a6d5b6
-    SSL_CTX_set_min_proto_version(ssl->ctx, 0);
a6d5b6
-    SSL_CTX_set_max_proto_version(ssl->ctx, TLS1_2_VERSION);
a6d5b6
+        SSL_CTX_set_max_proto_version(ssl->ctx, prot);
a6d5b6
+
a6d5b6
+        /* Now, we have to scan for minimal protocol version,
a6d5b6
+         *without allowing holes between min and max*/
a6d5b6
+#if SSL_OP_NO_TLSv1_3
a6d5b6
+        if ((prot == TLS1_3_VERSION) && (protocols & NGX_SSL_TLSv1_2)) {
a6d5b6
+            prot = TLS1_2_VERSION;
a6d5b6
+        }
a6d5b6
 #endif
a6d5b6
 
a6d5b6
-#ifdef TLS1_3_VERSION
a6d5b6
-    SSL_CTX_set_min_proto_version(ssl->ctx, 0);
a6d5b6
-    SSL_CTX_set_max_proto_version(ssl->ctx, TLS1_3_VERSION);
a6d5b6
+#ifdef SSL_OP_NO_TLSv1_1
a6d5b6
+        if ((prot == TLS1_2_VERSION) && (protocols & NGX_SSL_TLSv1_1)) {
a6d5b6
+            prot = TLS1_1_VERSION;
a6d5b6
+        }
a6d5b6
+#endif
a6d5b6
+#ifdef SSL_OP_NO_TLSv1_2
a6d5b6
+        if ((prot == TLS1_1_VERSION) && (protocols & NGX_SSL_TLSv1)) {
a6d5b6
+            prot = TLS1_VERSION;
a6d5b6
+        }
a6d5b6
 #endif
a6d5b6
+        SSL_CTX_set_min_proto_version(ssl->ctx, prot);
a6d5b6
+    }
a6d5b6
 
a6d5b6
 #ifdef SSL_OP_NO_COMPRESSION
a6d5b6
     SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_COMPRESSION);
a6d5b6
diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h
a6d5b6
index 329760d..5cee113 100644
a6d5b6
--- a/src/event/ngx_event_openssl.h
a6d5b6
+++ b/src/event/ngx_event_openssl.h
a6d5b6
@@ -152,6 +152,7 @@ typedef struct {
a6d5b6
 #endif
a6d5b6
 
a6d5b6
 
a6d5b6
+#define NGX_SSL_NO_PROT  0x0000
a6d5b6
 #define NGX_SSL_SSLv2    0x0002
a6d5b6
 #define NGX_SSL_SSLv3    0x0004
a6d5b6
 #define NGX_SSL_TLSv1    0x0008
a6d5b6
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c
a6d5b6
index a47d696..94f30db 100644
a6d5b6
--- a/src/http/modules/ngx_http_ssl_module.c
a6d5b6
+++ b/src/http/modules/ngx_http_ssl_module.c
a6d5b6
@@ -671,8 +671,7 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
a6d5b6
     ngx_conf_merge_value(conf->reject_handshake, prev->reject_handshake, 0);
a6d5b6
 
a6d5b6
     ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
a6d5b6
-                         (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
a6d5b6
-                          |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
a6d5b6
+                         0)
a6d5b6
 
a6d5b6
     ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
a6d5b6
                          NGX_SSL_BUFSIZE);
a6d5b6
diff --git a/src/mail/ngx_mail_ssl_module.c b/src/mail/ngx_mail_ssl_module.c
a6d5b6
index 7eae83e..8328560 100644
a6d5b6
--- a/src/mail/ngx_mail_ssl_module.c
a6d5b6
+++ b/src/mail/ngx_mail_ssl_module.c
a6d5b6
@@ -306,8 +306,7 @@ ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
a6d5b6
                          prev->prefer_server_ciphers, 0);
a6d5b6
 
a6d5b6
     ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
a6d5b6
-                         (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
a6d5b6
-                          |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
a6d5b6
+                         0);
a6d5b6
 
a6d5b6
     ngx_conf_merge_uint_value(conf->verify, prev->verify, 0);
a6d5b6
     ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1);
a6d5b6
diff --git a/src/stream/ngx_stream_ssl_module.c b/src/stream/ngx_stream_ssl_module.c
a6d5b6
index d8c0471..cef590d 100644
a6d5b6
--- a/src/stream/ngx_stream_ssl_module.c
a6d5b6
+++ b/src/stream/ngx_stream_ssl_module.c
a6d5b6
@@ -641,8 +641,7 @@ ngx_stream_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
a6d5b6
                          prev->prefer_server_ciphers, 0);
a6d5b6
 
a6d5b6
     ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
a6d5b6
-                         (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
a6d5b6
-                          |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
a6d5b6
+                         0);
a6d5b6
 
a6d5b6
     ngx_conf_merge_uint_value(conf->verify, prev->verify, 0);
a6d5b6
     ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1);