mailcow-dockerized-docs/docs/u_e-nginx.md

120 Zeilen
3,7 KiB
Markdown

2021-07-19 09:39:43 +02:00
## SSL
Please see [Advanced SSL](https://mailcow.github.io/mailcow-dockerized-docs/firststeps-ssl/) and explicitly check `ADDITIONAL_SERVER_NAMES` for SSL configuration.
Please do not add ADDITIONAL_SERVER_NAMES when you plan to use a different web root.
## New site
2018-07-20 09:22:23 +02:00
To create persistent (over updates) sites hosted by mailcow: dockerized, a new site configuration must be placed inside `data/conf/nginx/`:
2021-07-19 09:39:43 +02:00
A good template to begin with:
2018-07-20 09:22:23 +02:00
```
nano data/conf/nginx/my_custom_site.conf
```
2021-05-05 22:57:42 +02:00
``` hl_lines="16"
2020-06-01 10:14:25 +02:00
server {
ssl_certificate /etc/ssl/mail/cert.pem;
ssl_certificate_key /etc/ssl/mail/key.pem;
2021-05-05 22:57:42 +02:00
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305;
ssl_ecdh_curve X25519:X448:secp384r1:secp256k1;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1d;
ssl_session_tickets off;
2020-06-01 10:14:25 +02:00
index index.php index.html;
client_max_body_size 0;
2021-07-19 09:39:43 +02:00
# Location: data/web
2020-06-01 10:14:25 +02:00
root /web;
2021-07-19 09:39:43 +02:00
# Location: data/web/mysite.com
#root /web/mysite.com
2020-06-01 10:14:25 +02:00
include /etc/nginx/conf.d/listen_plain.active;
include /etc/nginx/conf.d/listen_ssl.active;
server_name mysite.example.org;
2021-04-26 13:21:07 +02:00
server_tokens off;
2020-06-01 10:14:25 +02:00
2021-07-19 09:39:43 +02:00
# This allows acme to be validated even with a different web root
2020-06-01 10:14:25 +02:00
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
2021-07-19 09:39:43 +02:00
rewrite /.well-known/acme-challenge/(.*) /$1 break;
root /web/.well-known/acme-challenge/;
2020-06-01 10:14:25 +02:00
}
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
}
```
2021-07-19 09:39:43 +02:00
## New site with proxy to a remote location
2020-10-08 13:45:52 +02:00
Another example with a reverse proxy configuration:
2021-07-19 09:39:43 +02:00
```
nano data/conf/nginx/my_custom_site.conf
```
2021-05-05 22:57:42 +02:00
``` hl_lines="16 28"
2020-10-08 13:45:52 +02:00
server {
ssl_certificate /etc/ssl/mail/cert.pem;
ssl_certificate_key /etc/ssl/mail/key.pem;
2021-05-05 22:57:42 +02:00
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305;
ssl_ecdh_curve X25519:X448:secp384r1:secp256k1;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1d;
ssl_session_tickets off;
2020-10-08 13:45:52 +02:00
index index.php index.html;
client_max_body_size 0;
root /web;
include /etc/nginx/conf.d/listen_plain.active;
include /etc/nginx/conf.d/listen_ssl.active;
server_name example.domain.tld;
2021-04-26 13:21:07 +02:00
server_tokens off;
2020-10-08 13:45:52 +02:00
location ^~ /.well-known/acme-challenge/ {
allow all;
default_type "text/plain";
}
if ($scheme = http) {
return 301 https://$host$request_uri;
}
location / {
2020-10-08 13:47:24 +02:00
proxy_pass http://service:3000/;
2020-10-08 13:45:52 +02:00
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 0;
}
}
```
2021-07-19 09:39:43 +02:00
## Config expansion in mailcows Nginx
2020-10-08 13:45:52 +02:00
2021-07-19 09:39:43 +02:00
The filename used for a new site is not important, as long as the filename carries a .conf extension.
2018-07-20 09:22:23 +02:00
It is also possible to extend the configuration of the default file `site.conf` file:
```
nano data/conf/nginx/site.my_content.custom
```
2021-07-19 09:39:43 +02:00
This filename does not need to have a ".conf" extension but follows the pattern `site.*.custom`, where `*` is a custom name.
2018-07-20 09:22:23 +02:00
If PHP is to be included in a custom site, please use the PHP-FPM listener on phpfpm:9002 or create a new listener in `data/conf/phpfpm/php-fpm.d/pools.conf`.
Restart Nginx (and PHP-FPM, if a new listener was created):
```
docker-compose restart nginx-mailcow
docker-compose restart php-fpm-mailcow
```
2021-07-19 09:39:43 +02:00