Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MailHog not working when using nginx proxy pass #117

Closed
prazmok opened this issue Oct 16, 2016 · 7 comments
Closed

MailHog not working when using nginx proxy pass #117

prazmok opened this issue Oct 16, 2016 · 7 comments

Comments

@prazmok
Copy link

prazmok commented Oct 16, 2016

I am using MailHog as a Docker container (using docker-compose) and for default configuration everything is OK. Unfortunately when I created Nginx proxy pass I get an error in browser console

VM61:35 WebSocket connection to 'ws://mailhog.sf3.dev:81/api/v2/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400

I guess it is bad configuration problem but as far as I know there is no option to configure MailHog image for docker-compose.

@blueimp
Copy link
Contributor

blueimp commented Oct 21, 2016

@prazmok
You can use mailhog in a docker-compose setup with nginx as proxy.
Here's a guide from the nginx homepage that will help you to set it up:
https://www.nginx.com/blog/websocket-nginx/

@JSchlarb
Copy link

@prazmok Add this to your nginx config ... That should do the trick. You must ensure that your mime.types are well configured

        chunked_transfer_encoding on;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
        proxy_redirect off;
        proxy_buffering off;

More https://www.nginx.com/blog/websocket-nginx/

@ian-kent
Copy link
Member

I've added a note to the configuration section of the docs - it's probably not in the most obvious place, but hopefully it'll help someone out!

@mkrsn
Copy link

mkrsn commented Sep 13, 2017

Here is the equivalent config for the Apache

<LocationMatch /api/v2/websocket>
    ProxyPass ws://127.0.0.1:3001/api/v2/websocket
</LocationMatch>

@opi
Copy link

opi commented Nov 14, 2017

Related comment about Apache proxy configuration #142 (comment)

rootpd pushed a commit to remp2020/remp that referenced this issue Jan 11, 2018
Websocket configuration added to nginx.conf fixed issue.

See:

- https://www.nginx.com/blog/websocket-nginx/
- mailhog/MailHog#117

Also fixed ENV variable for MailHog. Should be HOSTNAME. More-less just
cosmetic change - used for EHLO/HELO & mail header. Default value is
mailhog.example.

remp/remp#149
ayumi- pushed a commit to ayumi-/MailHog that referenced this issue Dec 8, 2018
@rounak-codiant
Copy link

rounak-codiant commented Jul 8, 2022

Below block worked for me

location ^~ /mailhog/ {
       chunked_transfer_encoding on;
       proxy_set_header X-NginX-Proxy true;
       proxy_pass http://localhost:8025/;        
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       proxy_http_version 1.1;
       proxy_redirect off;
       proxy_buffering off;
 }

@renanlucas07
Copy link

renanlucas07 commented Aug 9, 2022

Below block worked for me

location ^~ /mailhog/ {
       chunked_transfer_encoding on;
       proxy_set_header X-NginX-Proxy true;
       proxy_pass http://localhost:8025/;        
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       proxy_http_version 1.1;
       proxy_redirect off;
       proxy_buffering off;
 }

I used this inside a new server block together with my rails app configuration, i've added its own server_name and only / instead of /mailhog/ as the location

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants