简体   繁体   中英

Apache mod_proxy url encoding

I have a REST service that accepts parameters in a form /{parameter}

Also there is Apache2 that forwards requests to the websevice

<VirtualHost *:9091>
  AllowEncodedSlashes NoDecode
  LogLevel debug
  ProxyPass /webservice balancer://api/webservice

  <Proxy balancer://api>
     BalancerMember http://localhost:8030
  </Proxy>
</VirtualHost>

Parameters may contain encoded characters, like %2f (/)

The problem is that Apache encodes these characters again, and Webservice receives %252F instead of %2F

[Mon Oct 15 13:59:24 2012] [debug] mod_proxy_balancer.c(46): proxy: BALANCER: canonicalising URL //api/webservice/Interface GigabitEthernet1%2F0%2F2
[Mon Oct 15 13:59:24 2012] [debug] mod_proxy_balancer.c(581): proxy: BALANCER (balancer://api) worker (http://localhost:8030) rewritten to http://localhost:8030/Interface%20GigabitEthernet1%252F0%252F2%20Utilization

If I request the webservice directtly, Tomcat/Jetty handles it find and service receives correct parameter.

通过指定解决

ProxyPass /webservice balancer://api/webservice nocanon

A little bit off topic since this does not solve the problem with slashes but I will add it here anyway if anyone else runs in to the same problem as I had.

I had a similar problem that swedish special characters (åäö) in url parameters were not handled correctly when passed through apache proxy. It turned out that apache was doing fine but in the receiving tomcat instance the AJP-connector was missing URIEncoding configuration.

From my tomcat server.xml:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8080" URIEncoding="UTF-8"/>

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