[Original] Multiple domain names configured with different SSL certificates to access the same VPS

Taking CentOS7 Apache as an example, we will briefly describe how to configure different SSL certificates for multiple domain names and access the same VPS.

Prerequisite:
You need to prepare the SSL certificate file in advance (both self-signed certificate and certified certificate are acceptable, the SSL certificate in the example is from Let's Encrypt).

The following example realizes that both ho1ho.com and 50d.win can access the same website in HTTPS mode.

Create a new configuration file under /etc/httpd/conf.d: 50d.win.conf
vim /etc/httpd/conf.d/50d.win.conf

The content is as follows:
<VirtualHost *:443>
        ServerName www.50d.win
        ServerAlias 50d.win *.50d.win
        DocumentRoot /var/www/html

        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/50d.win/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/50d.win/privkey.pem
        SSLCertificateChainFile /etc/letsencrypt/live/50d.win/chain.pem
</VirtualHost>

In addition, create a new one: ho1ho.com.conf
vim /etc/httpd/conf.d/ho1ho.com.conf

The content is as follows:
<VirtualHost *:443>
        ServerName www.ho1ho.com
        ServerAlias ​​ho1ho.com *.ho1ho.com
        DocumentRoot /var/www/html

        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/ho1ho.com/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/ho1ho.com/privkey.pem
        SSLCertificateChainFile /etc/letsencrypt/live/ho1ho.com/chain.pem
</VirtualHost>

If you need to switch all HTTP to HTTPS, you can add the following forwarding rules: For example, modify the 50d.win.conf configuration file and add the following code:
<VirtualHost *:80>
        ServerName www.50d.win
        #ServerPath /domain
        ServerAlias 50d.win *.50d.win

        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

Note : If the SSL configuration of the default site is configured in the /etc/httpd/conf.d/ssl.conf file, then the ServerName needs to be explicitly specified in this file, otherwise the SSL configuration may appear when accessing the website error message. For example, assuming the default site's ServerName is www.ho1ho.com:
<VirtualHost _default_:443>
# General setup for the virtual host, inherited from global configuration
#DocumentRoot "/var/www/html"
#ServerName www.example.com:443
DocumentRoot "/var/www/html"
ServerName www.ho1ho.com
ServerAlias ​​ho1ho.com *.ho1ho.com


Reference article:

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326562951&siteId=291194637