Skip to content
Permalink
Browse files
mod_proxy_uwsgi: fix apache 2.4 integration with unix domain sockets
Example usage in apache conf:

    ProxyPass "/foo"  "unix:/var/run/uwsgi/foo.socket|uwsgi://uwsgi-uds-foo/"

Note: I use uwsgi-uds-foo as hostname instead of localhost because if
you have multiple entrie like these in the same apache conf, apache
thinks it is the same backend even though the unix socket path is
different. So it is mandatory to use different hostnames if you have
multiple app sockets.

Some references:
- https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=752783
- #973
- maybe #912
- #890
  • Loading branch information
niol committed Oct 2, 2015
1 parent 7019899 commit 6ce856c9fdb98833f9142f84c92b75f546b32dc2
Showing with 10 additions and 12 deletions.
  1. +10 −12 apache2/mod_proxy_uwsgi.c
@@ -67,20 +67,18 @@ static int uwsgi_canon(request_rec *r, char *url)
}
url += sizeof(UWSGI_SCHEME); /* Keep slashes */

// is it a unix socket ?
if (strlen(url) == 2) {
*sport = 0;
}
else {
err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
if (err) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"error parsing URL %s: %s", url, err);
return HTTP_BAD_REQUEST;
}
apr_snprintf(sport, sizeof(sport), ":%u", port);
err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
if (err) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"error parsing URL %s: %s", url, err);
return HTTP_BAD_REQUEST;
}

if (port != UWSGI_DEFAULT_PORT)

This comment has been minimized.

Copy link
@tarunkhanna

tarunkhanna Mar 14, 2018

Why is this change needed over here? It prevents proxying traffic on the default port 3031. So uswgi://127.0.0.1:3031 doesn't work, because apache tries to proxy it to uwsgi://127.0.0.1:0

This comment has been minimized.

Copy link
@niol

niol Mar 15, 2018

Author Contributor

You're right, this needs fixing. Maybe this would fix it:

--- a/apache2/mod_proxy_uwsgi.c
+++ b/apache2/mod_proxy_uwsgi.c
@@ -48,7 +48,6 @@ https://uwsgi-docs.readthedocs.io/en/latest/Apache.html#mod-proxy-uwsgi


 #define UWSGI_SCHEME "uwsgi"
-#define UWSGI_DEFAULT_PORT 3031

 module AP_MODULE_DECLARE_DATA proxy_uwsgi_module;

@@ -57,7 +56,7 @@ static int uwsgi_canon(request_rec *r, char *url)
 {
     char *host, sport[sizeof(":65535")];
     const char *err, *path;
-    apr_port_t port = UWSGI_DEFAULT_PORT;
+    apr_port_t port = 0;

     if (strncasecmp(url, UWSGI_SCHEME "://", sizeof(UWSGI_SCHEME) + 2)) {
         return DECLINED;
@@ -71,7 +70,7 @@ static int uwsgi_canon(request_rec *r, char *url)
         return HTTP_BAD_REQUEST;
     }

-    if (port != UWSGI_DEFAULT_PORT)
+    if (port != 0)
         apr_snprintf(sport, sizeof(sport), ":%u", port);
     else
         sport[0] = '\0';

This comment has been minimized.

Copy link
@tarunkhanna

tarunkhanna Mar 20, 2018

That looks right to me. Thanks.

This comment has been minimized.

Copy link
@tarunkhanna

tarunkhanna Mar 20, 2018

I think the issue 1491 is due to this bug.

apr_snprintf(sport, sizeof(sport), ":%u", port);
else
sport[0] = '\0';

if (ap_strchr(host, ':')) { /* if literal IPv6 address */
host = apr_pstrcat(r->pool, "[", host, "]", NULL);
}

0 comments on commit 6ce856c

Please sign in to comment.