Closed kustanbruno closed 1 year ago
I can't really say how IIS works, however it appears to be that IIS is closing the websocket connection. Each time the websocket reconnects Mailpit will refresh the messages automatically (so that part is expected). How long does it "hold" the connection for (it appears to immediately disconnect based on what I can see)?
So the issue here is your IIS proxy - if you find out why it's not holding the websocket connection (abnormal closure), then I suspect you'll have your solution. Sorry I can't be more help here, but I really have zero experience in over 15 years with IIS.
I ran into this when trying to set this up at work, too. Apparently, IIS's advanced request routing does not support permessage-deflate: https://serverfault.com/questions/1037407/websocket-based-website-behind-a-reverse-proxy-in-iis https://stackoverflow.com/questions/38933815/iis-8-websockets-with-permessage-deflate
I was able to get it working using the following workaround:
<serverVariables>
<set name="HTTP_SEC_WEBSOCKET_EXTENSIONS" value="" />
</serverVariables>
Thanks @doughless, I am sure this will help some. Given what you now know, do you think it is fairly easy to document the steps needed in order to set up a proxy for Mailpit using ISS? What I mean is, if I was to get a simple set of instructions of how to set it up on ISS, I could then document this in the Mailpit Wiki for other users to refer to.
@axllent Sure, this is what I put together, hopefully I remembered everything:
URL Rewrite 2.1 Application Request Routing 3.0
Open IIS Manager, select your server, then open the Application Request Routing Cache feature:
Next, click Server Proxy Settings...
Finally, check “Enable proxy” and click Apply.
Because Application Request Routing doesn’t work with the permessage_deflate WebSocket extension, you will need to add the HTTP_SEC_WEBSOCKET_EXTENSIONS server variable to URL Rewrite to allow your rewrite rules to remove the Sec-WebSocket-Extensions header value.
To do this, open IIS Manager, select your website, and open the URL Rewrite feature:
Then click on View Server Variables... and add a server variable named HTTP_SEC_WEBSOCKET_EXTENSIONS:
You can then close IIS Manager; you will need to manually add the URL Rewrite rules to your web.config, because URL Rewrite's UI doesn't allow setting server variables to an empty string value.
Edit the web.config for your website, and add the following rewrite rules:
<configuration>
<system.webServer>
<rewrite>
<rule name="MailPit Reverse Proxy" stopProcessing="true">
<match url="^(MP_WEBROOT.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{SERVER_PROTOCOL}" pattern="wss" negate="true" />
</conditions>
<action type="Rewrite" url="http://localhost:8025/{R:1}" />
<serverVariables>
<set name="HTTP_SEC_WEBSOCKET_EXTENSIONS" value="" />
</serverVariables>
</rule>
<rule name="MailPit WebSocket Reverse Proxy" stopProcessing="true">
<match url="^(MP_WEBROOT.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{SERVER_PROTOCOL}" pattern="wss" />
</conditions>
<action type="Rewrite" url="ws://localhost:8025/{R:1}" />
</rule>
</rewrite>
</system.webServer>
</configuration>
Thought I'd include a mention to you, @kustanbruno, to see if this helps you.
My apologies for the late reply @doughless - I was away for a few days. That is great, thank you! I have linked it to the Troubleshooting wiki page for now, but will hopefully (one one day not too far away) create and add it directly to a more suitable documentation website for Mailpit :+1:
Hi @doughless, thanks a lot, the configuration works. Your tutorial was really detailed and easy to follow. 👍
I had to add
We are upgrading from mailhog to mailpit. We are trying to use mailpit with IIS as reverse proxy, the configuration seems to be working, but the UI is always refreshing. There are no errors shown in the browser console nor in the output of mailpit. The network tab of the browser shows 2 request repeating:
I was able to replicate the problem in postman too. When connecting via ip address without IIS as reverse proxy, de output looks like this:
With IIS as reverse proxy, the output looks like this:
Mailhogs websocket endpoint seems to have no problem with the IIS as reverse proxy:
How should we troubleshoot this problem?