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

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

最近因为微信小程序的开发需要用到接口必须是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 文件,找到以下内容并去掉“#”:

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

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

语句:

  1. Listen 443
  2.  
  3. AddType application/x-x509-ca-cert .crt
  4. AddType application/x-pkcs7-crl .crl
  5.  
  6. SSLPassPhraseDialog builtin
  7. # Inter-Process Session Cache:
  8. # Configure the SSL Session Cache: First the mechanism
  9. # to use and second the expiring timeout (in seconds).
  10. #SSLSessionCache "dbm:C:/Apache2.2/logs/ssl_scache"
  11. SSLSessionCache "shmcb:D:/AppServ/Apache2.2/logs/ssl_scache(512000)"
  12. SSLSessionCacheTimeout 300
  13. # Semaphore:
  14. # Configure the path to the mutual exclusion semaphore the
  15. # SSL engine uses internally for inter-process synchronization.
  16. SSLMutex default
  17. ##
  18. ## SSL Virtual Host Context
  19. ##
  20. <VirtualHost 服务器IP:443>
  21. # General setup for the virtual host
  22. DocumentRoot "D:/AppServ/web/abc"
  23. ServerName a.mdaima:443
  24. ErrorLog "D:/AppServ/Apache2.2/logs/error.log"
  25. TransferLog "D:/AppServ/Apache2.2/logs/access.log"
  26. # SSL Engine Switch:
  27. # Enable/Disable SSL for this virtual host.
  28. SSLEngine on
  29. # SSL Cipher Suite:
  30. # List the ciphers that the client is permitted to negotiate.
  31. # See the mod_ssl documentation for a complete list.
  32. SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
  33. SSLHonorCipherOrder on
  34. # 添加 SSL 协议支持协议,去掉不安全的协议
  35. SSLProtocol all -SSLv2 -SSLv3
  36. # 证书公钥配置
  37. SSLCertificateFile "D:/AppServ/Apache2.2/conf/cert_1/public.pem"
  38. # 证书私钥配置
  39. SSLCertificateKeyFile "D:/AppServ/Apache2.2/conf/cert_1/abc.key"
  40. SSLCertificateChainFile "D:/AppServ/Apache2.2/conf/cert_1/chain.pem"
  41. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  42. SSLOptions +StdEnvVars
  43. </FilesMatch>
  44. <Directory "D:/AppServ/Apache2.2/cgi-bin">
  45. SSLOptions +StdEnvVars
  46. </Directory>
  47. BrowserMatch ".*MSIE.*" \
  48. nokeepalive ssl-unclean-shutdown \
  49. downgrade-1.0 force-response-1.0
  50. # Per-Server Logging:
  51. # The home of a custom SSL log file. Use this when you want a
  52. # compact non-error SSL logfile on a virtual host basis.
  53. #CustomLog "D:/AppServ/Apache2.2/logs/ssl_request.log" \
  54. # "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
  55. </VirtualHost>
  56. <VirtualHost 服务器IP:443>
  57. # General setup for the virtual host
  58. DocumentRoot "D:/AppServ/web/bcd"
  59. ServerName b.19jp.com:443
  60. ErrorLog "D:/AppServ/Apache2.2/logs/error_jk.log"
  61. TransferLog "D:/AppServ/Apache2.2/logs/access_jk.log"
  62. # SSL Engine Switch:
  63. # Enable/Disable SSL for this virtual host.
  64. SSLEngine on
  65. # SSL Cipher Suite:
  66. # List the ciphers that the client is permitted to negotiate.
  67. # See the mod_ssl documentation for a complete list.
  68. SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
  69. SSLHonorCipherOrder on
  70. # 添加 SSL 协议支持协议,去掉不安全的协议
  71. SSLProtocol all -SSLv2 -SSLv3
  72. # 证书公钥配置
  73. SSLCertificateFile "D:/AppServ/Apache2.2/conf/cert_2/public.pem"
  74. # 证书私钥配置
  75. SSLCertificateKeyFile "D:/AppServ/Apache2.2/conf/cert_2/bcd.key"
  76. SSLCertificateChainFile "D:/AppServ/Apache2.2/conf/cert_2/chain.pem"
  77. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  78. SSLOptions +StdEnvVars
  79. </FilesMatch>
  80. <Directory "D:/AppServ/Apache2.2/cgi-bin">
  81. SSLOptions +StdEnvVars
  82. </Directory>
  83. BrowserMatch ".*MSIE.*" \
  84. nokeepalive ssl-unclean-shutdown \
  85. downgrade-1.0 force-response-1.0
  86. # Per-Server Logging:
  87. # The home of a custom SSL log file. Use this when you want a
  88. # compact non-error SSL logfile on a virtual host basis.
  89. #CustomLog "D:/AppServ/Apache2.2/logs/ssl_request.log" \
  90. # "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
  91. </VirtualHost>

( 4 ) 重启 Apache。

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