We are configuring the certificates with mtls. The objective is server a service where the client must use a certificate to acess a endpoint and in parallel the service must use a certificate to ensure a https endpoint.
sudo apt update
sudo apt install nginx sudo ufw allow 'Nginx Full'mkdir /certs
cd /certsopenssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt cat ca.key > ca.pemopenssl genrsa -des3 -out user.key 4096
openssl req -new -key user.key -out user.csr openssl x509 -req -days 365 -in user.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out user.crt openssl pkcs12 -export -out user.pfx -inkey user.key -in user.crt -certfile ca.crtopenssl genrsa -out nginx.mssl.com.key 4096
openssl req -new -key nginx.mssl.com.key -out nginx.mssl.com.csr openssl x509 -req -days 365 -sha256 -in nginx.mssl.com.csr -CA ca.crt -CAkey ca.key -set_serial 1 -out nginx.mssl.com.crtsudo vim /etc/hosts
mkdir -p /usr/share/nginx/mssl cd /usr/share/nginx/mssl touch index.htmlcp -r /certs /etc/nginx
cd / chmod 777 -R /certs cd /etc/nginx/sites-available touch proxy.conf vim proxy.conf ln -s /etc/nginx/sites-available/proxy.conf /etc/nginx/sites-enabled/proxy.confsystemctl restart nginx
systemctl status nginxcd /certs curl --cert user.crt --key user.key --cacert ca.crt https://nginx.mssl.com:443