logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Reverse proxy configuration messing up HTTP POST requests
Author
maygamer.96



Joined: 03 Oct 2014
Posts: 1
Location: India

PostPosted: Wed 08 Dec '21 10:53    Post subject: Reverse proxy configuration messing up HTTP POST requests Reply with quote

Hi all,

Here is a scenario that exactly matches my current setup:

    - I have a WordPress+Apache site running at site.domain.co.in. The server runs Bitnami WordPress 5.5.3-1 (Debian, Apache, LAMP)

    - I have a PHP+Apache site running at tool.site.domain.co.in.

    - Both sites have their own individual HTTPS certificates from Let’s Encrypt.

    - I want to set up a path, site.domain.co.in/tool, which acts as a reverse proxy to tool.site.domain.co.in


I configured /opt/bitnami/apache2/conf/httpd.conf with the following configuration:

Code:

# Set up reverse proxy
ProxyRequests off
SSLProxyEngine On
ProxyPass /tool/ https://tool.site.domain.co.in/
ProxyHTMLURLMap https://tool.site.domain.co.in /tool

<Location /tool/>
        ProxyPassReverse /
        ProxyHTMLEnable On
        ProxyHTMLURLMap / /tool/
        RequestHeader unset Accept-Encoding
</Location>


This creates the reverse proxy, but the website is being broken because responses to POST requests are being returned as HTML pages instead of JSON data.

Response headers of the POST request for tool.site.domain.co.in:
Code:

HTTP/1.1 200 OK
Date: Wed, 08 Dec 2021 07:20:34 GMT
Server: Apache/2.4.51 () OpenSSL/1.0.2k-fips PHP/7.2.34
X-Powered-By: PHP/7.2.34
Content-Length: 238
Keep-Alive: timeout=5, max=96
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8


Response headers for same request from site.domain.co.in/tool:
Code:

HTTP/1.1 200 OK
Date: Wed, 08 Dec 2021 06:19:56 GMT
Server: Apache/2.4.51 () OpenSSL/1.0.2k-fips PHP/7.2.34
X-Frame-Options: SAMEORIGIN
X-Powered-By: PHP/7.2.34
X-Mod-Pagespeed: 1.13.35.2-0
Vary: Accept-Encoding
Cache-Control: max-age=0, no-cache
Content-Length: 1172
Keep-Alive: timeout=5, max=97
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8


Here's the response itself as it should be, and correctly renders at tool.site.domain.co.in:
Code:

{"date":["2011-01-01"],"level":[1,2,3],"sector":["rural","total","urban"],"default":{"date":"2011-01-01","level":3,"sector":"total","filters":{"Gender":"Total"}},"other_filters":[{"Gender":["Female","Male","Total"]}],"search_filter_id":1}


But here's what I get at site.domain.co.in/tool instead:
Code:

<html><body><p>{&quot;date&quot;:[&quot;2011-01-01&quot;],&quot;level&quot;:[1,2,3],&quot;sector&quot;:[&quot;rural&quot;,&quot;total&quot;,&quot;urban&quot;],&quot;default&quot;:{&quot;date&quot;:&quot;2011-01-01&quot;,&quot;level&quot;:3,&quot;sector&quot;:&quot;total&quot;,&quot;filters&quot;:{&quot;Gender&quot;:&quot;Total&quot;}},&quot;other_filters&quot;:[{&quot;Gender&quot;:[&quot;Female&quot;,&quot;Male&quot;,&quot;Total&quot;]}],&quot;search_filter_id&quot;:1}</p></body></html>


No clue what's missing that JSON is getting turned into HTML. Would appreciate any help.
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 312
Location: UK

PostPosted: Tue 14 Dec '21 18:08    Post subject: Reply with quote

Your post says the response data from the POST to tool.site.domain.co.in is JSON code, but I note your response headers say the Content-Type is text/html, not application/json.

Hence module mod_proxy_html assumes it needs to filter the response for HTML.

If tool.site.domain.co.in really is returning the wrong Content-Type, then if you can't fix that on the proxied server, you'll need to conditionally force the response header to application/json, before the response body gets passed back through mod_proxy_html.
Back to top


Reply to topic   Topic: Reverse proxy configuration messing up HTTP POST requests View previous topic :: View next topic
Post new topic   Forum Index -> Apache