关于Windows下的Apache多域名同IP、同443端口使用Https相关事项说明

服务器   发布日期:2023年05月21日   浏览次数:454

最近因为微信小程序的开发需要用到接口必须是https方式调用,所以就将自己的服务器从http升级到了https,但在升级调整过程中遇到了一些问题,经过反复测试最终还是找到的原因。

我使用的是阿云服务器,服务器上若干个网站都是采用二级域名的形式进行访问,比如我的域名19jp.com,还有一些子站是a.19jp.com、b.19jp.com等等。前期一直是http方式访问,没有任何问题,调整为https就遇到了很多问题。

两个https访问配置都完成后,发现第二个网站访问时浏览器显示的是第一个网站的证书,而将第一个网站的<VirtualHost 服务器IP:443>内容去掉,则显示正常,由此可以判断是只识别了第一个证书,经过网上查询资料,才知道了具体问题的原因。访问网站看到的证书不是我安装的那张,遇到这种问题,我们可以检查一下是否在服务器相同的IP以及端口上,只安装了一张证书,SSL协议是只允许在一个IP端口上返回一张证书。解决这个问题可以通过分配不同的端口号或者不同的IP地址。后来我将第二个网站换为444端口即正常了,但觉得体验不好并没有采用,只保留了第一个站的HTTPS方式。如果不是因为证书经费昂贵可以选择申请通配符类的证书就可以解决这个问题。

阿里提供的多个域名https常规设置方式的方法记录一下:

一、下载证书

文件说明:

1. 证书文件214524938199999.pem,包含两段内容,请不要删除任何一段内容。

2. 如果是证书系统创建的CSR,还包含:证书私钥文件214524938199999.key、证书公钥文件public.pem、证书链文件chain.pem。

二、配置服务器

( 1 ) 在Apache的安装目录下创建cert_1目录,并且将下载的全部文件拷贝到cert_1目录中。如果申请证书时是自己创建的CSR文件,请将对应的私钥文件放到cert_1目录下并且命名为214524938199999.key;

( 2 ) 多个证书请设置不同的路径用以区分

( 3 ) 打开 apache 安装目录下 conf 目录中的 httpd.conf 文件,找到以下内容并去掉“#”:

#LoadModule ssl_module modules/mod_ssl.so (如果找不到请确认是否编译过 openssl 插件)
#Include conf/extra/httpd-ssl.conf

( 3 ) 打开 apache 安装目录下 conf/extra/httpd-ssl.conf 文件 (也可能是conf.d/ssl.conf,与操作系统及安装方式有关), 在配置文件中查找以下配置

语句:

Listen 443 

AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl

SSLPassPhraseDialog  builtin
#   Inter-Process Session Cache:
#   Configure the SSL Session Cache: First the mechanism 
#   to use and second the expiring timeout (in seconds).
#SSLSessionCache         "dbm:C:/Apache2.2/logs/ssl_scache"
SSLSessionCache        "shmcb:D:/AppServ/Apache2.2/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300
#   Semaphore:
#   Configure the path to the mutual exclusion semaphore the
#   SSL engine uses internally for inter-process synchronization. 
SSLMutex default
##
## SSL Virtual Host Context
##
<VirtualHost 服务器IP:443>
    #   General setup for the virtual host
    DocumentRoot "D:/AppServ/web/abc"
    ServerName a.mdaima:443
    ErrorLog "D:/AppServ/Apache2.2/logs/error.log"
    TransferLog "D:/AppServ/Apache2.2/logs/access.log"
    #   SSL Engine Switch:
    #   Enable/Disable SSL for this virtual host.
    SSLEngine on
    #   SSL Cipher Suite:
    #   List the ciphers that the client is permitted to negotiate.
    #   See the mod_ssl documentation for a complete list.
    SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
    SSLHonorCipherOrder on
    # 添加 SSL 协议支持协议,去掉不安全的协议
    SSLProtocol all -SSLv2 -SSLv3
    # 证书公钥配置
    SSLCertificateFile "D:/AppServ/Apache2.2/conf/cert_1/public.pem"
    # 证书私钥配置
    SSLCertificateKeyFile "D:/AppServ/Apache2.2/conf/cert_1/abc.key"
    SSLCertificateChainFile "D:/AppServ/Apache2.2/conf/cert_1/chain.pem"
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory "D:/AppServ/Apache2.2/cgi-bin">
        SSLOptions +StdEnvVars
    </Directory>
    BrowserMatch ".*MSIE.*" \
             nokeepalive ssl-unclean-shutdown \
             downgrade-1.0 force-response-1.0
    #   Per-Server Logging:
    #   The home of a custom SSL log file. Use this when you want a
    #   compact non-error SSL logfile on a virtual host basis.
    #CustomLog "D:/AppServ/Apache2.2/logs/ssl_request.log" \
    #          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>       
         
<VirtualHost 服务器IP:443>
#   General setup for the virtual host
DocumentRoot "D:/AppServ/web/bcd"
ServerName b.19jp.com:443
ErrorLog "D:/AppServ/Apache2.2/logs/error_jk.log"
TransferLog "D:/AppServ/Apache2.2/logs/access_jk.log"
#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on
#   SSL Cipher Suite:
#   List the ciphers that the client is permitted to negotiate.
#   See the mod_ssl documentation for a complete list.
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
# 添加 SSL 协议支持协议,去掉不安全的协议
SSLProtocol all -SSLv2 -SSLv3
# 证书公钥配置
SSLCertificateFile "D:/AppServ/Apache2.2/conf/cert_2/public.pem"
# 证书私钥配置
SSLCertificateKeyFile "D:/AppServ/Apache2.2/conf/cert_2/bcd.key"
SSLCertificateChainFile "D:/AppServ/Apache2.2/conf/cert_2/chain.pem"
<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
</FilesMatch>
<Directory "D:/AppServ/Apache2.2/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>
BrowserMatch ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0
#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
#CustomLog "D:/AppServ/Apache2.2/logs/ssl_request.log" \
#          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>

( 4 ) 重启 Apache。

以上就是关于Windows下的Apache多域名同IP、同443端口使用Https相关事项说明的详细内容,更多关于关于Windows下的Apache多域名同IP、同443端口使用Https相关事项说明的资料请关注九品源码其它相关文章!