Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com

This Blog is protected by DMCA.com

huuphan.com. Powered by Blogger.

How to using NGINX Multiple ssl certificates on one ip

I experienced setup and configure nginx multiple domain on one VPS. In this tutorial, How to using NGINX Multiple ssl certificates on one ip. Multiple SSL Certificates use letsencrypt

How to using NGINX Multiple ssl certificates on one ip


Web server: Nginx
Two domain:
  1. domain1.com
  2. domain2.cm
IP VPS: 111.111.111.222

You buy VPS linux and configure multiple domain on one ip VPS server. I use VPS linode.com cheap 5 USD/month. I love it!

Nginx Redirect all HTTP requests to HTTPS


server {
        listen 80;
        listen [::]:80 ipv6only=on;
        if ($host = www.domain1.com) {
        return 301 https://$host$request_uri;
        }

        if ($host = www.domain2.com) {
        return 301 https://$host$request_uri;
        }
        server_name www.domain1.com domain1.com www.domain2.com domain2.com;
        return 444;

}

Nginx config for domain1.com


server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name www.domain1.com domain1.com;
        root /path/to/domain1/public_html;
        index index.php index.html index.htm;

        access_log off;
        #access_log /path/to/domain1/logs/access.log;
        error_log /path/to/domain1/logs/error.log;

        location / {
        try_files $uri $uri/ /index.php?$args;
        index index.html index.htm index.php;
        }

        ssl on;
        ssl_certificate /path/to/letsencrypt/fullchain.pem; # managed by Certbot
        ssl_certificate_key /path/to/letsencrypt/privkey.pem; # managed by Certbot
        ssl_trusted_certificate /path/to/letsencrypt/chain.pem;
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

Nginx config for domain2.com


server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name www.domain2.com domain2.com;
        root /path/to/domain2/public_html;
        index index.php index.html index.htm;

        access_log off;
        #access_log /path/to/domain2/logs/access.log;
        error_log /path/to/domain2/logs/error.log;


        location / {
        try_files $uri $uri/ /index.php?$args;
        index index.html index.htm index.php;
        }

        ssl on;
        ssl_certificate /path/to/letsencrypt/fullchain.pem; # managed by Certbot
        ssl_certificate_key /path/to/letsencrypt/privkey.pem; # managed by Certbot
        ssl_trusted_certificate /path/to/letsencrypt/chain.pem;
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com