Stella inattivaStella inattivaStella inattivaStella inattivaStella inattiva
 

 

per facilitarci la vita , visto che configureremo postfix e dovecot per l' uso di un DB , installeremo l' utility postfixadmin , ci aiuterà nella creazione delle caselle di posta, e gestione delle quote , graficamente non mi entusiasma ... ma fa il suo lavoro!!
 

visto che gestiremo tutto come utenti virtuali, dobbiamo creare un unico utente reale , non assegnargli una shell e creare la home /var/mail/vmail dove verranno salvate le mail


groupadd -g 5000 vmail
useradd -u 5000 -g vmail -s /usr/sbin/nologin -d /var/mail/vmail -m vmail

essendo postfix un app in php , dovremo installare un web server (nginx) , il supporto a php (7.3 al luglio 2020) e un DB (mariaDB):

apt-get install nginx mariadb-server php7.3-fpm php7.3-cli php7.3-imap php7.3-json php7.3-mysql php7.3-opcache php7.3-mbstring php7.3-readline

configurare una password di  root per il db MariaDB:

mysql_secure_installation

la procedura di setup ci chiederà alcune cose , tra cui la nuova password di root per il db:

 

Enter current password for root (enter for none): Press Enter
Set root password? [Y/n] Type Y
New password: Enter the password for the root user
Re-enter new password: Repeat the password
Remove anonymous users? [Y/n] Type Y
Disallow root login remotely? [Y/n] Type Y
Remove test database and access to it? [Y/n] Type Y
Reload privilege tables now? [Y/n] Type Y

 

a questo punto siamo pronti per installare postfixadmin, scarichiamolo da sourceforge (versione disponibile al luglio 2020 la 3.2 , se è passato del tempo andate prima sul sito e vedete se ne è uscita una nuova versione):

wget https://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-3.2/postfixadmin-3.2.tar.gz
tar xzf postfixadmin-3.2.tar.gz

una volta scompattato PostfixAdmin spostiamolo /var/www/html/postfixadmin    (debian /var/www/html , altre distro /var/www)

mv postfixadmin-3.2/ /var/www/html/postfixadmin
rm -f postfixadmin-3.2.tar.gz
mkdir /var/www/html/postfixadmin/templates_c

assegniamo la proprieta della directory a www-data  che sono l' utente con cui gira nginx e php:

chown -R www-data: /var/www/html/postfixadmin

ora colleghiamoci al DB per creare il db che userà postfixadmin e l' utente con cui lo gestirà

mysql -u root -p

cambiate "your_secret_password" con una password da voi scelta! di seguito dove troverete "your_secret_password" dovrete sempre mettere la vostra password

CREATE DATABASE postfixadmin;
GRANT ALL ON postfixadmin.* TO 'postfixadmin'@'localhost' IDENTIFIED BY 'your_secret_password';
FLUSH PRIVILEGES;

creiamo il file di configurazione  /var/www/html/postfixadmin/config.local.php e scriviamogli dentro:
(cambiando il dominio da "example.com" al vostro dominio
le caselle email indicate sotto sono degli alias, dovrete configurarle bene dopo!

 

<?php
$CONF['configured'] = true;

$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'your_secret_password';
$CONF['database_name'] = 'postfixadmin';

$CONF['default_aliases'] = array (
  'abuse'      => Questo indirizzo email è protetto dagli spambots. È necessario abilitare JavaScript per vederlo.',
  'hostmaster' => Questo indirizzo email è protetto dagli spambots. È necessario abilitare JavaScript per vederlo.',
  'postmaster' => Questo indirizzo email è protetto dagli spambots. È necessario abilitare JavaScript per vederlo.',
  'webmaster'  => Questo indirizzo email è protetto dagli spambots. È necessario abilitare JavaScript per vederlo.'
);

$CONF['fetchmail'] = 'NO';
$CONF['show_footer_text'] = 'NO';

$CONF['quota'] = 'YES';
$CONF['domain_quota'] = 'YES';
$CONF['quota_multiplier'] = '1024000';
$CONF['used_quotas'] = 'YES';
$CONF['new_quota_table'] = 'YES';

$CONF['aliases'] = '0';
$CONF['mailboxes'] = '0';
$CONF['maxquota'] = '0';
$CONF['domain_quota_default'] = '0';
?>

la configurazione di sopra indica il tipo di database da usare, l' utente e la password da usare per collegarsi al db, disabilita fetchmail e abilita la quota

ora installiamo i dati di base per far funzionare il tutto:
sudo -u www-data php /var/www/html/postfixadmin/public/upgrade.php

quindi creiamo l' utente amministratore sempre da riga di comando, attenzione, ci verra chiesto un nume utente nel formato mail, ma questa mail non viene creata in automatico la dovremo creare noi se ci interessa che sia reale

bash /var/www/html/postfixadmin/scripts/postfixadmin-cli admin add

 

Welcome to Postfixadmin-CLI v0.2
---------------------------------------------------------------
Admin:
> nomeutente @ ilmioservermail.ilmiodominio.it
Password:
> La_mia_Password_supersegreta_con_2_numer1
Password (again):
> La_mia_Password_supersegreta_con_2_numer1
Super admin:
(Super admins have access to all domains, can manage domains and admin accounts.) (y/n)
> y
Domain:
> ilmiodominio.it
Active: (y/n)
> y

The admin nomeutente @ ilmioservermail.ilmiodominio.it has been added!
---------------------------------------------------------------

 


 

a questo punto installiamo let's encript , la guida originale, lascio sotto i comandi fa installare python-certbot-nginx dal ppa, su debian 10 lo potete installare col comando

 

apt install python-certbot-nginx 
certbot --nginx

 

sudo apt-get install software-properties-common lsb-release
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo install python-certbot-nginx
sudo certbot --nginx

 

per funzionare a questo punto dovete avere le porte 80 e 443 aperte su internet , se siete dietro nat dovrete fare il port forwarding e comunque il dominio che volete  certificare dovrà essere gia dichiarato sui dns e puntare al vostro indirizzo ip (ad esempio lamiaposta.ilmiosito.it) pena il non funzionamento di let's encrypt

 

l' esecuzione di certbot ci chiedera alcune cose :

 

certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): nomeutente @ ilmioservermail.altromiodominio.it

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: a

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: n
No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated) (Enter 'c' to cancel): ilmioservermail.ilmiodominio.it
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for ilmioservermail.ilmiodominio.it
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/default

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/default

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://ilmioservermail.ilmiodominio.it 

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=ilmioservermail.ilmiodominio.it 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/ilmioservermail.ilmiodominio.it/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/ilmioservermail.ilmiodominio.it/privkey.pem
Your cert will expire on 2020-10-18. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

 

 

 

a questo punto se provate con un browser ad aprire il vostro sito, vi risponderà ngnix con la schermata di benvenuto!!!

 certbot ha modificato il file /etc/nginx/sites-enabled/default aggiungendo alcune righe per il nostro sito,

la situazione che ora abbiamo è :
l' utente chiama un sito col nostro indirizzo ip , viene utilizzata la parte _ ossia il default di nginx

l' utente chiama il sito http://ilmioservermail.ilmiodominio.it  viene utilizzato la parte ilmioservermail.ilmiodominio.it del file di configurazione

sinceramente ho preferito separare la parte default da quella relativa al sito vero e proprio , anche perchè postfixadmin vuole che dichiariamo come document_root il path /var/www/html/postfixadmin/public , il che avrebbe dato fastidio in seguito, quindi ... dopo aver penato vari giorni , aver studiato un pò di nginx che non avevo mai usato , aver trovato la soluzione per utilizzare document root variabili in base alla directory che viene chiamata , ho deciso come consigliato da alcuni amici di creare subdomain differenti, ognuno col suo certificato ....

quindi , il file 

 

/etc/nginx/sites-enabled/default

 

è diventato :

 

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
access_log /var/log/nginx/access.generic.log;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}

 

 il file

/etc/nginx/sites-enabled/ilmioservermail.ilmiodominio.it.conf

 

in pratica facciamo si che quando viene chiamato https://ilmioservermail.ilmiodominio.it/ venga restituita la root /var/www/html , mentre quando viene chiamato
https://ilmioservermail.ilmiodominio.it/padmin/  viene fatto settata come root directory /var/www/html/postfixadmin/config e viene fatto un rewrite della richiesta in modo da sostituire padmin con postfixadmin ed eliminare public

 

server {
root /var/www/html;
access_log /var/log/nginx/access.server1.log;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name ilmioservermail.ilmiodominio.it; # managed by Certbot

location /padmin {
return 301 https://$host/padmin/;

location ^~ /padmin/ {
root /var/www/html/postfixadmin/public/;
rewrite ^/padmin/(.*)$ /postfixadmin/public/$1 last;
location ~ \.php$ {
rewrite ^/padmin/(.*)$ /postfixadmin/public/$1;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}
}
location ~ /\.ht {
deny all;
}location / {
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;#
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/ilmioservermail.ilmiodominio.it/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/ilmioservermail.ilmiodominio.it/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = ilmioservermail.ilmiodominio.it) {
return 301 https://$host$request_uri;<br< a="">> } # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name ilmioservermail.ilmiodominio.it;
return 404; # managed by Certbot
}

 

a questo punto ho deciso di fare anche un secondo subdomain ...

postfixadmin.ilmiodominio.it , per far cio' va creato il file

 

server {
listen 443;
root /var/www/html/postfixadmin/public;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name postfixadmin.ilmiodominio.it; # managed by Certbot
access_log /var/log/nginx/access.postfixadmin.log;
location / {
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;#
}
ssl_certificate /etc/letsencrypt/live/postfixadmin.ilmiodominio.it/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/postfixadmin.ilmiodominio.it/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 80;
if ($host = postfixadmin.ilmiodominio.it) {
return 301 https://$host$request_uri;<br< a="">> } # managed by Certbot
server_name postfixadmin.ilmiodominio.it;
return 404; # managed by Certbot

 

visto che abbiamo dichiarato un nuovo subdomain e abbiamo indicato nella configurazione un nuovo certificato , creiamolo !!!
 

#certbot certonly

Saving debug log to /var/log/letsencrypt/letsencrypt.log

How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Nginx Web Server plugin (nginx)
2: Spin up a temporary webserver (standalone)
3: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-3] then [enter] (press 'c' to cancel): 1
Plugins selected: Authenticator nginx, Installer None
Please enter in your domain name(s) (comma and/or space separated) (Enter 'c'
to cancel): postfixadmin.ilmiodominio.it
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for postfixadmin.ilmiodominio.it
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/postfixadmin.ilmiodominio.it/fullchain.pem
Your key file has been saved at:/etc/letsencrypt/live/postfixadmin.ilmiodominio.it/privkey.pem
Your cert will expire on 2020-10-24. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

 

 

 

ora possiamo riavviare nginx con:

service nginx restart

 

e se non abbiamo sbagliato niente , ci ritroveremo che puntando al nostro sito si apre la pagina di postfixadmin ... se invece nginx non riparte controlliamo il log in

/var/log/nginx/error.log

 

e vediamo cosa abbiamo sbagliato

 

 

spet precedenti:

introduzione

 

step successivi :

postfix e dovecot

rspamd dkim dovecot dns

roundcube

test finali

ps. ogni 3 mesi dovremo rinnovare i certificati!!!!