From dd7e4fd34042483cc90ee2762f4b507fd6637d37 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Wed, 16 Jun 2021 23:49:38 +0200 Subject: [PATCH] nginx: add support for unix domain sockets Support for UNIX domain socket was introduced in NGINX version 0.8.21 [1]. One can use this to create option to have the stub_status plugin reachable via a socket-only server. [1] http://nginx.org/en/docs/http/ngx_http_core_module.html#listen --- configure.ac | 12 ++++++++++++ src/nginx.c | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index bcfb8cf57..ae2fb08c7 100644 --- a/configure.ac +++ b/configure.ac @@ -2322,6 +2322,12 @@ if test "x$with_libcurl" = "xyes"; then [have_curlopt_timeout="no"], [[#include ]] ) + + AC_CHECK_DECL(CURLOPT_UNIX_SOCKET_PATH, + [have_curlopt_unix_socket_path="yes"], + [have_curlopt_unix_socket_path="no"], + [[#include ]] + ) fi fi @@ -2373,6 +2379,12 @@ if test "x$with_libcurl" = "xyes"; then [Define if libcurl supports CURLOPT_TIMEOUT_MS option.] ) fi + + if test "x$have_curlopt_unix_socket_path" = "xyes"; then + AC_DEFINE([HAVE_CURLOPT_UNIX_SOCKET_PATH], [1], + [Define if libcurl supports CURLOPT_UNIX_SOCKET_PATH option.] + ) + fi fi AC_SUBST(BUILD_WITH_LIBCURL_CFLAGS) diff --git a/src/nginx.c b/src/nginx.c index 0da66ce2e..08293a506 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -40,6 +40,7 @@ static char *verify_peer; static char *verify_host; static char *cacert; static char *timeout; +static char *sock; static CURL *curl; @@ -47,8 +48,9 @@ static char nginx_buffer[16384]; static size_t nginx_buffer_len; static char nginx_curl_error[CURL_ERROR_SIZE]; -static const char *config_keys[] = { - "URL", "User", "Password", "VerifyPeer", "VerifyHost", "CACert", "Timeout"}; +static const char *config_keys[] = {"URL", "User", "Password", + "VerifyPeer", "VerifyHost", "CACert", + "Timeout", "Socket"}; static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); static size_t nginx_curl_callback(void *buf, size_t size, size_t nmemb, @@ -98,6 +100,8 @@ static int config(const char *key, const char *value) { return config_set(&cacert, value); else if (strcasecmp(key, "timeout") == 0) return config_set(&timeout, value); + else if (strcasecmp(key, "socket") == 0) + return config_set(&sock, value); else return -1; } /* int config */ @@ -161,6 +165,12 @@ static int init(void) { } #endif +#ifdef HAVE_CURLOPT_UNIX_SOCKET_PATH + if (sock != NULL) { + curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, sock); + } +#endif + return 0; } /* void init */ -- 2.47.2