You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Daniel <df...@gmail.com> on 2017/09/01 19:57:23 UTC

Re: [users@httpd] mod_rewrite + proxy + unix socket results in 400 bad request

AFAIK you can't use variables of captured groups when using sockets,
but I don't have an answer to why. To check If I'm correct you could
try using a tcp port instead of socket.

2017-08-31 18:06 GMT+02:00 David Mugnai <dv...@gnx.it>:
> Excerpts from Luca Toscano's message of agosto 31, 2017 1:55 :
>
>> Hi David,
>>
>> 2017-08-29 17:41 GMT+02:00 David Mugnai <dv...@gnx.it>:
>>
>>> Hi,
>>>
>>> I'm trying to configure a virtual host that, based on the host name,
>>> forwards the request on a backend server listening on an unix socket.
>>>
>>> My apache version is 2.4.18 as shipped by Ubuntu 16.04
>>>
>>> The configuration I've tried so far is:
>>>
>>> <VirtualHost *:80>
>>>        ServerAdmin webmaster@localhost
>>>        DocumentRoot /var/www/html
>>>        LogLevel trace2
>>>
>>>        UseCanonicalName Off
>>>
>>>        RewriteEngine On
>>>        RewriteCond %{HTTP_HOST} ^(.+)\.example.com
>>>        RewriteRule "(.*)"
>>> "unix:/home/user/%1/server.sock|http://127.0.0.1$1
>>> [P,NE]
>>>
>>>        ErrorLog ${APACHE_LOG_DIR}/error.log
>>>        CustomLog ${APACHE_LOG_DIR}/access.log combined
>>> </VirtualHost>
>>>
>>> The rewrite module works as expected (in the log file I can see the full
>>> path to the unix socket), but trying to access the web server results in
>>> a "400 Bad Request" *without* the involvment of the backend server.
>>>
>>> I made a test with ProxyPass directive, and it works, but obviously is
>>> not what I want:
>>>
>>> <VirtualHost *:80>
>>>        ServerAdmin webmaster@localhost
>>>        DocumentRoot /var/www/html
>>>        LogLevel trace2
>>>
>>>        UseCanonicalName Off
>>>
>>>        ProxyPass / unix:/home/user/subdomain1/server.sock|
>>> http://127.0.0.1/
>>>        ProxyPassReverse / unix:/home/user/subdomain1/server.sock|
>>> http://127.0.0.1/
>>>
>>>        ErrorLog ${APACHE_LOG_DIR}/error.log
>>>        CustomLog ${APACHE_LOG_DIR}/access.log combined
>>> </VirtualHost>
>>>
>>> How can I fix it?
>>>
>>
>> Didn't have much time to try this use case manually but I have a couple of
>> suggestions:
>>
>> 1) Do you find any log in the error_log that could give us some clue about
>> the 400 returned? (maybe increasing the LogLevel to debug or trace)
>
> up to trace8 :) unfortunately nothing relevant ends into the logs.
> I can see mod_rewrite doing its work but nothing about the 400
>
>> 2) Have you tried
>> https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypassmatch ?
>
> Correct me if I am wrong, but ProxyPassMatch cannot match against the
> hostname, isn't it?
>
> David
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>



-- 
Daniel Ferradal
IT Specialist

email         dferradal at gmail.com
linkedin     es.linkedin.com/in/danielferradal

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite + proxy + unix socket results in 400 bad request

Posted by Daniel <df...@gmail.com>.
IIRC it was by design yes, but I don't know the reasons behind it,
perhaps the dev mailing list or some developers reading this can
provide more information. You could also try #httpd-dev at Freenode.

I think you could reach your goals without using captured groups
though, I see in the initial virtualhost you shared, that there is no
servername, so probably you are only using that one for a few or
several hostnames, so you could just define separate virtualhosts with
their names and their own socket path, you can use "in-config"
variables with Define directive to avoid typing the same thing several
times or even use mod_macro, here is a brief example with in-config
variables:

Define subdomain1 printers
<VirtualHost *:80>
       ServerAdmin webmaster@localhost
       ServerName ${subdomain1}.example.com
       DocumentRoot /var/www/html
       LogLevel trace2

       UseCanonicalName Off

       ProxyPass / unix:/home/user/${subdomain1}/server.sock|http://127.0.0.1/
       ProxyPassReverse /
unix:/home/user/${subdomain1}/server.sock|http://127.0.0.1/
...
</VirtualHost>

Define subdomain2 mail
<VirtualHost *:80>
       ServerAdmin webmaster@localhost
       ServerName ${subdomain2}.example.com
....etc

2017-09-04 11:03 GMT+02:00 David Mugnai <dv...@gnx.it>:
> Excerpts from Daniel's message of settembre 1, 2017 9:57 :
>>
>> AFAIK you can't use variables of captured groups when using sockets,
>> but I don't have an answer to why. To check If I'm correct you could
>> try using a tcp port instead of socket.
>
>
> You are right, switching the test environment to tcp works.
> Unfortunatley this not works with our planned deploy; do you know if the
> limitation is by desing?
>
> david
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>



-- 
Daniel Ferradal
IT Specialist

email         dferradal at gmail.com
linkedin     es.linkedin.com/in/danielferradal

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite + proxy + unix socket results in 400 bad request

Posted by David Mugnai <dv...@gnx.it>.
Excerpts from Daniel's message of settembre 1, 2017 9:57 :
> AFAIK you can't use variables of captured groups when using sockets,
> but I don't have an answer to why. To check If I'm correct you could
> try using a tcp port instead of socket.

You are right, switching the test environment to tcp works.
Unfortunatley this not works with our planned deploy; do you know if the
limitation is by desing?

david

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org