Search code examples
apachehttppostproxyoctoprint

OctoPrint through Apache reverse proxy 400 bad request on login


Background

Specs:

OctoPrint 1.3.4 (master branch)

Apache/2.4.10 (Debian) using mod_proxy

I'm trying to run a reverse proxy on my Apache server to OctoPrint as is specified in the developer's Reverse proxy configuration examples.

This is my Apache proxy configuration inside my vhost:

<Location "/3d">
            AuthType Basic
            AuthName "-----------"
            AuthBasicProvider file
            AuthUserFile "------------------"
            Require user -------------

            ProxyPass "http://192.168.------:5000"
            ProxyPassReverse "http://192.168.------:5000"

            RequestHeader set X-SCRIPT-NAME /3d/
            RequestHeader set X-SCHEME https
</Location>

However, on successfully loading the OctoPrint interface through the proxy, I am unable to login, getting the error:

POST https://-----------/3d/api/login 400 (Bad Request) in the network tab on Chrome.

Here's the request headers of both the proxy:

POST /3d/api/login HTTP/1.1
Host: -------------
Connection: keep-alive
Content-Length: 16
Authorization: Basic -----------------
Origin: ----------------
User-Agent: --------------
Content-Type: application/json; charset=UTF-8
Accept: application/json, text/javascript, */*; q=0.01
Cache-Control: no-cache
X-Requested-With: XMLHttpRequest
X-Api-Key: -------------------
Referer: https://----------/3d
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
Cookie: session_P443=----------------; PHPSESSID=-------------; JSESSIONID=dummy

And directly from the local IP (not through the proxy):

POST /api/login HTTP/1.1
Host: 192.168.0.-------:5000
Connection: keep-alive
Content-Length: 16
Origin: http://192.168.0.------:5000
User-Agent: -------------
Content-Type: application/json; charset=UTF-8
Accept: application/json, text/javascript, */*; q=0.01
Cache-Control: no-cache
X-Requested-With: XMLHttpRequest
X-Api-Key: --------------
Referer: http://192.168.0.------:5000/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
Cookie: session_P5000=-------------------------------

Question

What is causing this POST https://-----------/3d/api/login 400 (Bad Request) error and how do I fix?

Thanks ahead!


Solution

  • Nevermind, Mod_Security was blocking the POST request for containing JSON.

    Look at the logs dummy.