@@ -354,8 +354,11 @@ static void ngx_http_upstream_check_begin_handler(ngx_event_t *event);
354
354
static void ngx_http_upstream_check_connect_handler (ngx_event_t * event );
355
355
356
356
#if (NGX_HTTP_SSL )
357
- static void ngx_http_upstream_do_ssl_handshake (ngx_event_t * event );
358
- static void ngx_ups_ssl_handshake (ngx_connection_t * c );
357
+ static void ngx_http_upstream_do_ssl_handshake (ngx_event_t * event );
358
+ static void ngx_ups_ssl_handshake (ngx_connection_t * c );
359
+ static int is_https_check (ngx_http_upstream_check_peer_t * peer ) {
360
+ return strcmp ((const char * )peer -> conf -> check_type_conf -> name .data , "https" ) == 0 ;
361
+ }
359
362
#endif
360
363
361
364
static void ngx_http_upstream_check_peek_handler (ngx_event_t * event );
@@ -1089,6 +1092,9 @@ ngx_http_upstream_check_add_timers(ngx_cycle_t *cycle) {
1089
1092
1090
1093
ucscf = peer [i ].conf ;
1091
1094
cf = ucscf -> check_type_conf ;
1095
+ if (is_https_check (& peer [i ])) {
1096
+ ngx_ssl_create (& ucscf -> ssl , NGX_SSL_SSLv3 | NGX_SSL_TLSv1 ,0 );
1097
+ }
1092
1098
1093
1099
if (cf -> need_pool ) {
1094
1100
peer [i ].pool = ngx_create_pool (ngx_pagesize , cycle -> log );
@@ -1214,7 +1220,7 @@ ngx_http_upstream_check_connect_handler(ngx_event_t *event) {
1214
1220
1215
1221
peer = event -> data ;
1216
1222
ucscf = peer -> conf ;
1217
- int is_https_check_type = strcmp (( const char * ) peer -> conf -> check_type_conf -> name . data , "https" ) == 0 ;
1223
+ int is_https_check_type = is_https_check ( peer ) ;
1218
1224
1219
1225
if (peer -> pc .connection != NULL ) {
1220
1226
c = peer -> pc .connection ;
@@ -1258,7 +1264,7 @@ ngx_http_upstream_check_connect_handler(ngx_event_t *event) {
1258
1264
c -> sendfile = 0 ;
1259
1265
c -> read -> log = c -> log ;
1260
1266
c -> write -> log = c -> log ;
1261
- c -> pool = peer -> pool ;
1267
+ c -> pool = ngx_create_pool ( ngx_pagesize , ngx_cycle -> log ) ;
1262
1268
#if (NGX_HTTP_SSL )
1263
1269
if (is_https_check_type && rc == NGX_AGAIN ) {
1264
1270
c -> write -> handler = ngx_http_upstream_do_ssl_handshake ;
@@ -1283,6 +1289,18 @@ ngx_http_upstream_check_connect_handler(ngx_event_t *event) {
1283
1289
}
1284
1290
1285
1291
#if (NGX_HTTP_SSL )
1292
+ static void free_SSL_data (ngx_http_upstream_check_peer_t * peer ) {
1293
+ ngx_connection_t * c = peer -> pc .connection ;
1294
+ if (is_https_check (peer ) &&
1295
+ c -> ssl ) {
1296
+ ngx_ssl_free_buffer (c );
1297
+ c -> ssl -> no_wait_shutdown = 1 ;
1298
+ c -> ssl -> no_send_shutdown = 1 ;
1299
+ ngx_ssl_shutdown (c );
1300
+ c -> ssl = NULL ;
1301
+ }
1302
+ }
1303
+
1286
1304
static void ngx_http_upstream_do_ssl_handshake (ngx_event_t * event ) {
1287
1305
long rc ;
1288
1306
ngx_connection_t * c ;
@@ -1291,9 +1309,7 @@ static void ngx_http_upstream_do_ssl_handshake(ngx_event_t *event) {
1291
1309
c = event -> data ;
1292
1310
peer = c -> data ;
1293
1311
ucscf = peer -> conf ;
1294
- ucscf -> ssl .buffer_size = NGX_SSL_BUFSIZE ;
1295
- ucscf -> ssl .ctx = SSL_CTX_new (SSLv23_method ());
1296
- rc = ngx_ssl_create_connection (& ucscf -> ssl , c , NGX_SSL_BUFFER |NGX_SSL_CLIENT );
1312
+ rc = ngx_ssl_create_connection (& ucscf -> ssl , c , NGX_SSL_CLIENT );
1297
1313
if (rc != NGX_OK ) {
1298
1314
return ;
1299
1315
}
@@ -1307,9 +1323,7 @@ static void ngx_http_upstream_do_ssl_handshake(ngx_event_t *event) {
1307
1323
c -> tcp_nodelay = NGX_TCP_NODELAY_SET ;
1308
1324
rc = ngx_ssl_handshake (c );
1309
1325
if (rc != NGX_OK && rc != NGX_AGAIN ) {
1310
- ngx_ssl_shutdown (peer -> pc .connection );
1311
- SSL_CTX_free (ucscf -> ssl .ctx );
1312
- ucscf -> ssl .ctx = NULL ;
1326
+ free_SSL_data (peer );
1313
1327
return ;
1314
1328
}
1315
1329
if (rc == NGX_AGAIN ) {
@@ -1330,9 +1344,11 @@ ngx_ups_ssl_handshake(ngx_connection_t *c) {
1330
1344
if (c -> ssl && c -> ssl -> handshaked ) {
1331
1345
rc = SSL_get_verify_result (c -> ssl -> connection );
1332
1346
if (rc != X509_V_OK ) {
1347
+ /*
1333
1348
ngx_log_error(NGX_LOG_ERR, c->log, 0,
1334
1349
"upstream SSL certificate verify error: (%l:%s)",
1335
1350
rc, X509_verify_cert_error_string(rc));
1351
+ */
1336
1352
}
1337
1353
}
1338
1354
peer -> state = NGX_HTTP_CHECK_CONNECT_DONE ;
@@ -2759,15 +2775,7 @@ ngx_http_upstream_check_status_update(ngx_http_upstream_check_peer_t *peer,
2759
2775
}
2760
2776
2761
2777
#if (NGX_HTTP_SSL )
2762
- int is_https_check_type = strcmp ((const char * )peer -> conf -> check_type_conf -> name .data , "https" ) == 0 ;
2763
- if (is_https_check_type ) {
2764
- ngx_http_upstream_check_srv_conf_t * ucscf ;
2765
- ucscf = peer -> conf ;
2766
- if (ucscf -> ssl .ctx ) {
2767
- ngx_ssl_shutdown (peer -> pc .connection );
2768
- SSL_CTX_free (ucscf -> ssl .ctx );
2769
- }
2770
- }
2778
+ free_SSL_data (peer );
2771
2779
#endif
2772
2780
peer -> shm -> access_time = ngx_current_msec ;
2773
2781
}
@@ -2795,6 +2803,10 @@ ngx_http_upstream_check_clean_event(ngx_http_upstream_check_peer_t *peer) {
2795
2803
} else {
2796
2804
ngx_close_connection (c );
2797
2805
peer -> pc .connection = NULL ;
2806
+ if (c -> pool ) {
2807
+ ngx_destroy_pool (c -> pool );
2808
+ c -> pool = NULL ;
2809
+ }
2798
2810
}
2799
2811
}
2800
2812
0 commit comments