You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by /U <um...@comcast.net> on 2009/08/01 02:20:57 UTC

[users@httpd] Forcing URL Rewrite before Proxy pass

Apache: 2.2.0

I need to
   a) require SSL on requests to /secure (i.e., http://server/secure ->
https://server/secure)
   b) and as the second step, offload (proxy) https://server/secure to
http://server:8080/secure

I thought I could accomplish (a) using mod_rewrite and (b) using Proxy pass
as follows:

RewriteEngine On
RewriteLog  "/tmp/http.log"
RewriteLogLevel 9
RewriteCond %{SERVER_PORT}!443$
RewriteRule ^/secure(.*) https://%{HTTP_HOST}:443/secure$1 [R=301,L]

<Proxy balancer://clusterx>
BalancerMember http://localhost:8080/
</Proxy>
ProxyPass /secure balancer://clusterx/

However, this does not work. A request http://server/secure is directly
forwarded to
http://server:8080/secure


Is there anyway to force Rewrite before proxy pass?

Pl help..

Thanx,

/U


-- 
View this message in context: http://www.nabble.com/Forcing-URL-Rewrite-before-Proxy-pass-tp24764763p24764763.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Forcing URL Rewrite before Proxy pass

Posted by André Warnier <aw...@ice-sa.com>.
/U wrote:
> Thanks Andre and Jorge. I combined your suggestions to 
> arrive at the following:
> 
>        ProxyRequests Off
>       
>       <Proxy balancer://clusterx>
>          BalancerMember http://server:8080/
>       </Proxy>
> 
>       <VirtualHost *:80>
>         Redirect /securehttps://server/secure
>        </VirtualHost>
> 
>       <VirtualHost *:443>
>             ProxyPass /secure balancer://clusterx/
>             ProxyPassReverse /secure balancer://clusterx/
>             ProxyPreserveHost On
>        </VirtualHost>
> 
> 
> What happens is that the first mapping works fine:
> 
>     http://server/seure/index.html     ==>  https://server/secure/index.html
> 
> But the mapping
>      https://server/secure/index.html    ==>  http://server:8080
> 
> does not work and I get a 404:
> 
>     logs# cat ssl_access_log
>     10.xx.xx.xx - - [01/Aug/2009:12:43:43 -0700] "GET /secure/index.html
> HTTP/1.1" 404 294
> 
I am not so knowledgeable in the Proxy* series of directives, but one 
idea is that you need to make sure *inside the VirtualHost* that you 
turn on all the required options.
You show only a snippet, so there is no way to tell.
It is possible that some/all of the Proxy* stuff does not automatically 
get "inherited" from the "main" part of the configuration (the part that 
is outside of both <VirtualHost> sections).

To summarise : move any Proxy* directives which may be left outside of 
<VirtualHost> sections, inside the 2d <VirtualHost> section, and try again.


If you want to know more :

Once you start using <VirtualHost> sections, the way of looking at your 
configuration and at Apache in general changes :

- whatever is in the "main" section (outside any <VirtualHost>) is read 
first when Apache starts up, and only sets default values.
- what is inside the <VirtualHost> section of the VirtualHost which 
processes a any given request, overrides these default values, just for 
the current request.
The general case is thus that the main default values are automatically 
inherited by each VirtualHost.
But some specific directives are not.  The documentation of these 
directives usually tells you when that is the case, but they are not 
always clear about this.
In doubt thus, duplicate the directives in each VirtualHost where you 
want them to apply.






---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Forcing URL Rewrite before Proxy pass

Posted by /U <um...@comcast.net>.
Thanks Andre and Jorge. I combined your suggestions to 
arrive at the following:

       ProxyRequests Off
      
      <Proxy balancer://clusterx>
         BalancerMember http://server:8080/
      </Proxy>

      <VirtualHost *:80>
        Redirect /securehttps://server/secure
       </VirtualHost>

      <VirtualHost *:443>
            ProxyPass /secure balancer://clusterx/
            ProxyPassReverse /secure balancer://clusterx/
            ProxyPreserveHost On
       </VirtualHost>


What happens is that the first mapping works fine:

    http://server/seure/index.html     ==>  https://server/secure/index.html

But the mapping
     https://server/secure/index.html    ==>  http://server:8080

does not work and I get a 404:

    logs# cat ssl_access_log
    10.xx.xx.xx - - [01/Aug/2009:12:43:43 -0700] "GET /secure/index.html
HTTP/1.1" 404 294

Why does the ProxyPass in the 443 VirtualHost not work?
How can I trace the operation of Proxypass?

Thanks for all your assistance.

/U


Jorge Schrauwen-3 wrote:
> 
> If you want to go SSL here is an easier way to check for SSL
> 
> RewriteEngine On
> RewriteCond %{HTTPS} !=on [NC]
> RewriteRule ^/secure(.*) https://%{SERVER_NAME}/secure$1 [R,L]
> 
> You way also want to look at the P flag to proxy the request.
> http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteflags
> 'proxy|P' (force proxy) This flag forces the substitution part to be
> internally sent as a proxy request and immediately (rewrite processing
> stops
> here) put through the proxy
> module<http://httpd.apache.org/docs/2.2/mod/mod_proxy.html>.
> You must make sure that the substitution string is a valid URI (typically
> starting with http://*hostname*) which can be handled by the Apache proxy
> module. If not, you will get an error from the proxy module. Use this flag
> to achieve a more powerful implementation of the
> ProxyPass<http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass>directive,
> to map remote content into the namespace of the local server.
> 
> Note: mod_proxy <http://httpd.apache.org/docs/2.2/mod/mod_proxy.html> must
> be enabled in order to use this flag.
> Whic is probably what you wanted from the beginning.
> 
> 
> Also if you go André's way, you can do a
> Redirect /secure https://yourdomain/secure
> 
> that should be faster than rewrite.
> 
> ~Jorge
> 
> 
> On Sat, Aug 1, 2009 at 12:24 PM, André Warnier <aw...@ice-sa.com> wrote:
> 
>> /U wrote:
>>
>>> Apache: 2.2.0
>>>
>>> I need to
>>>   a) require SSL on requests to /secure (i.e., http://server/secure ->
>>> https://server/secure)
>>>   b) and as the second step, offload (proxy) https://server/secure to
>>> http://server:8080/secure
>>>
>>>  I don't know the details, but the following may work :
>>
>> You may need is 2 <VirtualHost> sections, as follows :
>>
>> main config :
>> Listen *:80
>> Listen *:443
>>
>> ...
>> <VirtualHost *:80>
>> ...
>>
>>  RewriteEngine On
>>> RewriteLog  "/tmp/http.log"
>>> RewriteLogLevel 9
>>> RewriteCond %{SERVER_PORT}!443$
>>> RewriteRule ^/secure(.*) https://%{HTTP_HOST}:443/secure$1 [R=301,L]
>>>
>>>  ...
>> </VirtualHost>
>>
>> <VirtualHost *:443>
>> .. your proxy stuff ..
>> </VirtualHost>
>>
>> The general idea being :
>> - the first VirtualHost acts as the default (and only) host for all
>> requests to port 80.  If there is a request to /secure, it sends an
>> external
>> re-direct to the browser, re-directing it to HTTPS on port 443
>> - the second VirtualHost acts as the default (and only) host on port 443.
>>  It terminates SSL and proxies the requests to your Tomcat (I suppose)
>> via
>> HTTP.
>> (Note that you could also use mod_jk or mod_proxy_ajp there, probably
>> more
>> efficiently.)
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server
>> Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>  "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Forcing-URL-Rewrite-before-Proxy-pass-tp24764763p24772107.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Forcing URL Rewrite before Proxy pass

Posted by Jorge Schrauwen <jo...@gmail.com>.
If you want to go SSL here is an easier way to check for SSL

RewriteEngine On
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^/secure(.*) https://%{SERVER_NAME}/secure$1 [R,L]

You way also want to look at the P flag to proxy the request.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteflags
'proxy|P' (force proxy) This flag forces the substitution part to be
internally sent as a proxy request and immediately (rewrite processing stops
here) put through the proxy
module<http://httpd.apache.org/docs/2.2/mod/mod_proxy.html>.
You must make sure that the substitution string is a valid URI (typically
starting with http://*hostname*) which can be handled by the Apache proxy
module. If not, you will get an error from the proxy module. Use this flag
to achieve a more powerful implementation of the
ProxyPass<http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass>directive,
to map remote content into the namespace of the local server.

Note: mod_proxy <http://httpd.apache.org/docs/2.2/mod/mod_proxy.html> must
be enabled in order to use this flag.
Whic is probably what you wanted from the beginning.


Also if you go André's way, you can do a
Redirect /secure https://yourdomain/secure

that should be faster than rewrite.

~Jorge


On Sat, Aug 1, 2009 at 12:24 PM, André Warnier <aw...@ice-sa.com> wrote:

> /U wrote:
>
>> Apache: 2.2.0
>>
>> I need to
>>   a) require SSL on requests to /secure (i.e., http://server/secure ->
>> https://server/secure)
>>   b) and as the second step, offload (proxy) https://server/secure to
>> http://server:8080/secure
>>
>>  I don't know the details, but the following may work :
>
> You may need is 2 <VirtualHost> sections, as follows :
>
> main config :
> Listen *:80
> Listen *:443
>
> ...
> <VirtualHost *:80>
> ...
>
>  RewriteEngine On
>> RewriteLog  "/tmp/http.log"
>> RewriteLogLevel 9
>> RewriteCond %{SERVER_PORT}!443$
>> RewriteRule ^/secure(.*) https://%{HTTP_HOST}:443/secure$1 [R=301,L]
>>
>>  ...
> </VirtualHost>
>
> <VirtualHost *:443>
> .. your proxy stuff ..
> </VirtualHost>
>
> The general idea being :
> - the first VirtualHost acts as the default (and only) host for all
> requests to port 80.  If there is a request to /secure, it sends an external
> re-direct to the browser, re-directing it to HTTPS on port 443
> - the second VirtualHost acts as the default (and only) host on port 443.
>  It terminates SSL and proxies the requests to your Tomcat (I suppose) via
> HTTP.
> (Note that you could also use mod_jk or mod_proxy_ajp there, probably more
> efficiently.)
>
>
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>  "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Forcing URL Rewrite before Proxy pass

Posted by André Warnier <aw...@ice-sa.com>.
/U wrote:
> Apache: 2.2.0
> 
> I need to
>    a) require SSL on requests to /secure (i.e., http://server/secure ->
> https://server/secure)
>    b) and as the second step, offload (proxy) https://server/secure to
> http://server:8080/secure
> 
I don't know the details, but the following may work :

You may need is 2 <VirtualHost> sections, as follows :

main config :
Listen *:80
Listen *:443

...
<VirtualHost *:80>
...

> RewriteEngine On
> RewriteLog  "/tmp/http.log"
> RewriteLogLevel 9
> RewriteCond %{SERVER_PORT}!443$
> RewriteRule ^/secure(.*) https://%{HTTP_HOST}:443/secure$1 [R=301,L]
> 
...
</VirtualHost>

<VirtualHost *:443>
.. your proxy stuff ..
</VirtualHost>

The general idea being :
- the first VirtualHost acts as the default (and only) host for all 
requests to port 80.  If there is a request to /secure, it sends an 
external re-direct to the browser, re-directing it to HTTPS on port 443
- the second VirtualHost acts as the default (and only) host on port 
443.  It terminates SSL and proxies the requests to your Tomcat (I 
suppose) via HTTP.
(Note that you could also use mod_jk or mod_proxy_ajp there, probably 
more efficiently.)



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Forcing URL Rewrite before Proxy pass

Posted by /U <um...@comcast.net>.
Thanks for the note.

When I use the P flag with the RewriteRule, ProxyPass
fails, since I do not have an SSLProxy.

What I have is this:

       (Apache web server)  <-----> Tomcat servlet container

What I need is to:
    - require all requests for ^/secure/... to be made thru https
    - terminate SSL on Apache
    - after SSL termination, forward all requests for ^/secure/ 
       to http://localhost:8080/secure

I do not want to proxy SSL onto omcat from Apache.
Am I headed in the right direction with regards to the configuration?

Thanx!

/U


Eric Covener wrote:
> 
> On Fri, Jul 31, 2009 at 8:20 PM, /U<um...@comcast.net> wrote:
>>
>> Apache: 2.2.0
>>
>> I need to
>>   a) require SSL on requests to /secure (i.e., http://server/secure ->
>> https://server/secure)
>>   b) and as the second step, offload (proxy) https://server/secure to
>> http://server:8080/secure
>>
>> I thought I could accomplish (a) using mod_rewrite and (b) using Proxy
>> pass
>> as follows:
>>
>> RewriteEngine On
>> RewriteLog  "/tmp/http.log"
>> RewriteLogLevel 9
>> RewriteCond %{SERVER_PORT}!443$
>> RewriteRule ^/secure(.*) https://%{HTTP_HOST}:443/secure$1 [R=301,L]
>>
>> <Proxy balancer://clusterx>
>> BalancerMember http://localhost:8080/
>> </Proxy>
>> ProxyPass /secure balancer://clusterx/
>>
>> However, this does not work. A request http://server/secure is directly
>> forwarded to
>> http://server:8080/secure
>>
>>
>> Is there anyway to force Rewrite before proxy pass?
> 
> Use the "P" flag in rewrite instead of ProxyPass, and you can control
> the flow directly.
> 
> 
> 
> -- 
> Eric Covener
> covener@gmail.com
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Forcing-URL-Rewrite-before-Proxy-pass-tp24764763p24765222.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Forcing URL Rewrite before Proxy pass

Posted by Eric Covener <co...@gmail.com>.
On Fri, Jul 31, 2009 at 8:20 PM, /U<um...@comcast.net> wrote:
>
> Apache: 2.2.0
>
> I need to
>   a) require SSL on requests to /secure (i.e., http://server/secure ->
> https://server/secure)
>   b) and as the second step, offload (proxy) https://server/secure to
> http://server:8080/secure
>
> I thought I could accomplish (a) using mod_rewrite and (b) using Proxy pass
> as follows:
>
> RewriteEngine On
> RewriteLog  "/tmp/http.log"
> RewriteLogLevel 9
> RewriteCond %{SERVER_PORT}!443$
> RewriteRule ^/secure(.*) https://%{HTTP_HOST}:443/secure$1 [R=301,L]
>
> <Proxy balancer://clusterx>
> BalancerMember http://localhost:8080/
> </Proxy>
> ProxyPass /secure balancer://clusterx/
>
> However, this does not work. A request http://server/secure is directly
> forwarded to
> http://server:8080/secure
>
>
> Is there anyway to force Rewrite before proxy pass?

Use the "P" flag in rewrite instead of ProxyPass, and you can control
the flow directly.



-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org