简体   繁体   中英

How to re-write request URL with Apache HTTP Server?

My requirement is quite simple. I have a forward proxy in Apache and clients send SOAP calls to this forward proxy. This proxy needs to be able to rewrite the URL to something else, and forward the request yet another proxy.

This is my configuration so far:

<Proxy *>
Order Allow,Deny
Allow from all

RewriteEngine  on
RewriteRule    "^(.*)"  "https://test.salesforce.com/services/Soap/u/20.0"  [P]

</Proxy>

AllowCONNECT 80 443 553 22


# This is the main proxy configuration
ProxyPass /Salesforce http://user:pwd@10.54.167.70:80/ retry=1 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse /Salesforce http://user:pwd@10.54.167.70:80/

I am not sure if my rewrite rule is at all correct. Can any you please confirm?

The configuration looks so very ugly and I'm not sure what you are trying to do, but still, it really looks as you are just trying to reverse proxy, not forward proxy, I'll try to help with the mistakes anyways the best I can.

The Rewrite, if you are trying to capture a group, I guess you want to use it later:

RewriteRule ^(.*) https://test.salesforce.com/services/Soap/u/20.0/$1  [P,L]

But why a Rewrite? , you are using the P flag, which is used to proxy, what you are trying there is not a rewrite , this a reverse proxy, so why not just:

ProxyPass / https://test.salesforce.com/services/Soap/u/20.0/

AllowConnect, this is to allow SSL forward proxy connections, why do you specify port 80? You want them to go through SSL too? Looks very wrong.

AllowCONNECT 443 553 22

And about your last directives, you need to match slashes for them to work correctly, and also reverse proxy connections should be specified more specific first. First, make sure you do want a forward proxy, but in a forward proxy you can allow/disallow a backend but you don't specify backends, if you specify the backend that is a reverse proxy:

This is briefly what I would go for interpreting what you want, removing all forward proxy related directives:

ProxyPass /Salesforce/ http://user:pwd@10.54.167.70/ retry=1 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse /Salesforce/ http://10.54.167.70/

SSLProxyEngine on
ProxyPass / https://test.salesforce.com/services/Soap/u/20.0/
ProxyPassReverse / https://test.salesforce.com/services/Soap/u/20.0/

This answer could be refined if you can specify further the "forward proxy" part you mention.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM