How to run multiple sites on the one server

Preface

I ran a mail system on my server first. Then I want to run blog system too, but it is hard for me such a outsider to do this. After a long time learning on internet, I leart how to do this.

The solution in iRedmail system

This mail system would listen 80 port and redirect to 443, the https port. The config file for 80 port is in /etc/nginx/sites-available/00-default.conf which does not need to be changed as we also want https. So we only need to change config file for 443 port:

/etc/nginx/sites-available/00-default-ssl.conf

1
vim /etc/nginx/sites-available/00-default-ssl.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#
# Note: This file must be loaded before other virtual host config files,
#
# HTTPS
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name mail.bbb.enterprises;

root /var/www/html;
index index.php index.html;

include /etc/nginx/templates/misc.tmpl;
include /etc/nginx/templates/ssl.tmpl;
include /etc/nginx/templates/iredadmin.tmpl;
include /etc/nginx/templates/roundcube.tmpl;
include /etc/nginx/templates/sogo.tmpl;
include /etc/nginx/templates/netdata.tmpl;
include /etc/nginx/templates/php-catchall.tmpl;
include /etc/nginx/templates/stub_status.tmpl;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/letsencrypt/live/gitea.bbb.enterprises/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/gitea.bbb.enterprises/privkey.pem;
server_name gitea.bbb.enterprises;
location / {
proxy_pass http://localhost:3001/; # this is reverse proxy
}
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
allow all;
root /var/www/example.com/;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/letsencrypt/live/doublefire.chen.bbb.enterprises/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/doublefire.chen.bbb.enterprises/privkey.pem;
server_name doublefire.chen.bbb.enterprises;
root /var/www/blog; # this is vhosts
index index.html;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/letsencrypt/live/umami.bbb.enterprises/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/umami.bbb.enterprises/privkey.pem;
server_name umami.bbb.enterprises;
location / {
proxy_pass http://localhost:3000/; # this is reverse proxy
}
}

This config will result that different user from different domain can be redirected to different destinations(web redirectory or other port).