Using Prosody with a HTTP Reverse Proxy

It's been a while since I first installed prosody on I use it to experiments with my bots, to keep contact with the XMPP community and discover new cool stuffs to do. Recently I struggled a bit because I wanted to hide the prosody small HTTP server behind my Proxy. For various reasons, I still use Apache 2.4 and I could not get it to work with prosody. I mostly use the HTTP server for bosh authentication with Converse.js and with the http_upload module. When the 5281 port was accessible and Prosody handled the requests directly on the internet it worked well. But when I followed the documentation to use a proxy, it stopped working. All my PUT requests got a 404 error. I tested my setup with Slixmpp and the http_upload example.

Here is my configuration before the fix:


Main config

https_ports = { 5281 }
https_interfaces = {  "", "::1" }
trusted_proxies = { "", "::1"}


Component "" "http_upload"
       http_max_content_size = 10485760
       http_external_url = ""

Apache VirtualHost

ProxyPass / http://localhost:5280/
ProxyPassReverse / http://localhost:5280/



DEBUG    SEND: <iq id="23efd54cf4b2487386852e800f2ea411" to="" type="get"><request xmlns="urn:xmpp:http:upload:0" filename="robot.png" size="118037" content-type="image/png" /></iq>
DEBUG    RECV: <iq type="result" id="23efd54cf4b2487386852e800f2ea411" from="" to=""><slot xmlns="urn:xmpp:http:upload:0"><get url="" /><put url="" /></slot></iq>
ERROR    Could not upload file: 404 (<!DOCTYPE html>
<meta charset="utf-8">
<title>404 Not Found</title>


Mar 21 10:02:42 c2s5586c8e88960 debug   Received[c2s]: <iq id='23efd54cf4b2487386852e800f2ea411' type='get' to=''>
Mar 21 10:02:42 c2s5586c8e88960 debug   Given upload slot "au5rOiUMomJbDI3q/robot.png"
Mar 21 10:02:42 c2s5586c8e88960 debug   Sending[c2s]: <iq type='result' id='23efd54cf4b2487386852e800f2ea411' from='' to=''>
Mar 21 10:02:42 socket  debug   server.lua: accepted new client connection from ::1:49436 to 5280
Mar 21 10:02:42 http.server debug   Firing event: PUT /upload/au5rOiUMomJbDI3q/robot.png
Mar 21 10:02:42 http.server debug   Firing event: PUT localhost/upload/au5rOiUMomJbDI3q/robot.png

What is important to see is the second event:

PUT localhost/upload/au5rOiUMomJbDI3q/robot.png

on a working configuration it is


The fix

After a small discussion with Link Mauve from JabberFr, he suggested me to use setup the proxy to tell him to force its headers:


    RequestHeader set Host ""
    ProxyPreserveHost On
    ProxyPass / http://localhost:5280/
    ProxyPassReverse / http://localhost:5280/


proxy_set_header Host "";

Two small lines and now it is working as expected :-).