Skip to content

Commit

Permalink
Added docs for reverse proxy guide.
Browse files Browse the repository at this point in the history
Included example configurations for nginx and apache2.
  • Loading branch information
tk-nguyen authored and marlonbaeten committed May 15, 2023
1 parent 5fe8df5 commit 39039b2
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The default SMTP port is 1025, the default HTTP port is 1080. You can configure
```sh
docker run --rm -p 3000:1080 -p 2525:1025 marlonb/mailcrab:latest
```

## Host

You can specify the host address Mailcrab will listen on for HTTP request using
Expand Down Expand Up @@ -84,6 +84,10 @@ docker run --rm --env MAILCRAB_PREFIX=emails -p 1080:1080 -p 1025:1025 marlonb/m

The web interface will also be served at [http://localhost:1080/emails/](http://localhost:1080/emails/)

### Reverse proxy

See [the reverse proxy guide](./Reverse_proxy.md).

### docker compose

Usage in a `docker-compose.yml` file:
Expand Down
103 changes: 103 additions & 0 deletions Reverse_proxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Reverse proxy guide

If you want to put MailCrab behind a reverse proxy, you can use the following configurations:

## Nginx

```nginx
server {
listen 80;
server_name <your server name>;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://<your MailCrab server>:1080;
}
location /ws {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://<your MailCrab server>:1080;
}
}
```

If you are using `MAILCRAB_PREFIX`, for example `MAILCRAB_PREFIX=emails`:

```nginx
location /emails {
...
}
location /emails/ws {
...
}
```

## Apache2
- For apache2 version 2.4.47 and later:

Enable `mod_proxy` and `mod_proxy_http`. Then you can use the following snippet:

```apache
<VirtualHost *:80>
ProxyPass "/ws" "http://<your MailCrab server>:1080/ws" upgrade=websocket
ProxyPass "/" "http://<your MailCrab server>:1080/"
ProxyPassReverse "/" "http://<your MailCrab server>:1080/"
</VirtualHost>
```

If you are using `MAILCRAB_PREFIX`, for example `MAILCRAB_PREFIX=emails`:

```apache
<VirtualHost *:80>
ProxyPass "/emails/ws" "http://<your MailCrab server>:1080/emails/ws" upgrade=websocket
ProxyPass "/emails" "http://<your MailCrab server>:1080/emails"
ProxyPassReverse "/emails" "http://<your MailCrab server>:1080/emails"
</VirtualHost>
```

- For apache2 version 2.4.46 and earlier:

Enable `mod_proxy`, `mod_proxy_http` and `mod_proxy_wstunnel`. Then you can use the following snippet:

```apache
<VirtualHost *:80>
ProxyPass "/ws" "ws://<your MailCrab server>:1080/ws"
ProxyPass "/" "http://<your MailCrab server>:1080/"
ProxyPassReverse "/" "http://<your MailCrab server>:1080/"
</VirtualHost>
```

If you are using `MAILCRAB_PREFIX`, for example `MAILCRAB_PREFIX=emails`:

```apache
<VirtualHost *:80>
ProxyPass "/emails/ws" "ws://<your MailCrab server>:1080/emails/ws"
ProxyPass "/emails" "http://<your MailCrab server>:1080/emails"
ProxyPassReverse "/emails" "http://<your MailCrab server>:1080/emails"
</VirtualHost>
```

## Other reverse proxies

MailCrab is using 3 endpoints in its backend:

- `/api` for the messages.
- `/ws` for client-backend communication (using WebSocket).
- `/static` for assets.

Just proxy those 3 endpoints to the backend and it should work properly.

If you are using `MAILCRAB_PREFIX`, add the prefix before each endpoint: `/<prefix>/{api, ws, static}`

0 comments on commit 39039b2

Please sign in to comment.