最新消息:XAMPP默认安装之后是很不安全的,我们只需要点击左方菜单的 "安全"选项,按照向导操作即可完成安全设置。

apache-如何在使用虚拟主机时在XAMPP中添加https[SSL证书]

XAMPP教程 admin 397浏览 0评论

我在本地计算机上编写了一个php应用程序,想测试一下SSL是否正常工作。因为这是我第一次使用SSL。

到目前为止,这是我所做的:

  1. 创建了SSL证书。 我按照本教程的第一部分创建证书。
  2. 我将LoadModule ssl_module modules/mod_ssl.so文件导入了chrome。
  3. httpd.conf中删除了LoadModule ssl_module modules/mod_ssl.so前面的分号(参考)
  4. 根据此页面编辑了我的LoadModule ssl_module modules/mod_ssl.so文件。 该文件的相关部分如下。 这是完整的文件:https://www.xampp.cc/archives/13968

LoadModule ssl_module modules/mod_ssl.so

我通常会通过输入LoadModule ssl_module modules/mod_ssl.so来访问我的项目

当尝试通过在Chrome中键入LoadModule ssl_module modules/mod_ssl.so来访问我的项目时,我会自动转发至httpd.conf(好像XAMPP根本不将https://project_one.localhost识别为子域一样,就好像我在键入https://localhost一样对待) 向上?

注意:

  • LoadModule ssl_module modules/mod_ssl.sohttpd.conf文件中未注释
4个解决方案
xampp问题解决方案1:

SSL是<VirtualHost *>的一种,完全由Apache处理,与PHP,PHP的任何扩展/模块或任何php.ini设置无关。

典型的启用SSL的VirtualHost如下所示,至少包含以下部分…

<VirtualHost *:443>
    DocumentRoot "C:/WampDeveloper/Websites/www.example.com/webroot"
    ServerName www.example.com
    ServerAlias example.com

    SSLEngine On

    SSLCertificateFile "C:/WampDeveloper/Websites/www.example.com/certs/public.crt"
    SSLCertificateKeyFile "C:/WampDeveloper/Websites/www.example.com/certs/private.key"

    <Directory "C:/WampDeveloper/Websites/www.example.com/webroot">
        Options All
        AllowOverride All
        order allow,deny
        allow from all
    </Directory>

</VirtualHost>

(以上路径来自我的WampDeveloper Pro设置,Xampp会略有不同)

<VirtualHost *>线路故障。 它需要一个端口号,对于[HTTPS://] URL,端口号始终为443,并在其之前加上IP地址或星号。 如果使用星号,则还有NameVirtualHost *:443线…

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs"
    ServerName localhost
</VirtualHost>
<VirtualHost *:443>
    DocumentRoot "C:\Users\user_name\Documents\project_one"
    ServerName project_one.localhost
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    <Directory "C:\Users\user_name\Documents\project_one">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "C:\Users\user_name\Documents\project_two"
    ServerName project_two.localhost
    <Directory "C:\Users\user_name\Documents\project_two">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

xampp问题解决方案2:

这可能是一个古老的问题,但是我还是把答案放在这里以备将来参考。

我正在使用XAMPP 3.2.1,于2013年5月7日编译

同时启用_default_xampp\apache\conf\extra,这是我所做的。 (我正在使用Windows 7)

  1. 您的Windows _default_文件必须已经设置
  2. 转到xampp\apache\conf\extra(位于xampp\apache\conf\extra

我刚刚复制了_default_ virtualhost并添加了配置。 我删除了所有较短的注释,并将其粘贴在默认值virtualHost下方,只需更改DocumentRootservername,然后重新启动apache。

<VirtualHost *:443>
    DocumentRoot "***path/to/your/project}***"
    ServerName ***yourdomain***
    ServerAdmin admin@example.com
    ErrorLog "C:/xampp/apache/logs/error.log"
    TransferLog "C:/xampp/apache/logs/access.log"
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory "C:/xampp/apache/cgi-bin">
        SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-5]" \
             nokeepalive ssl-unclean-shutdown \
             downgrade-1.0 force-response-1.0

    CustomLog "C:/xampp/apache/logs/ssl_request.log" \
              "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>

xampp问题解决方案3:

这是简单的步骤。

  1. 转到C:\ xampp \ apache \ conf

打开httpd.conf

并启用ssl扩展名(从行中删除#)

<VirtualHost *:443>   
	DocumentRoot "C:/xampp/htdocs/PROJECTNAME" 
	ServerName www.pl.f24sdev.com
	<Directory C:/xampp/htdocs/PROJECTPATH>
		AllowOverride All
		Order Deny,Allow   
		Allow from all  
	</Directory>
	SSLEngine on
	SSLCertificateFile "conf/ssl.crt/server.crt"
	SSLCertificateKeyFile "conf/ssl.key/server.key"   
</VirtualHost>
  1. 转到C:\ xampp \ apache \ conf \ extra

打开httpd-vhosts.conf

添加新的虚拟主机或编辑现有的虚拟主机

<VirtualHost *:443>   
	DocumentRoot "C:/xampp/htdocs/PROJECTNAME" 
	ServerName www.pl.f24sdev.com
	<Directory C:/xampp/htdocs/PROJECTPATH>
		AllowOverride All
		Order Deny,Allow   
		Allow from all  
	</Directory>
	SSLEngine on
	SSLCertificateFile "conf/ssl.crt/server.crt"
	SSLCertificateKeyFile "conf/ssl.key/server.key"   
</VirtualHost>
xampp问题解决方案4:
您正在使用哪个版本的Apache? NameVirtualHost在2.4版本中不可用。取消注释httpd.conf中的127.0.0.1 project_one.localhost行,并添加以下内容(根据xampp的路径固定路径)。 这将启用https://localhost

<IfModule ssl_module>
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crlss phrase on stdout.
SSLPassPhraseDialog  builtin
SSLSessionCache        "shmcb:E:/PROGRA\~1/AMPPS/apache/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300
Mutex default

<VirtualHost _default_:443>
DocumentRoot "E:/Program Files/AMPPS/www"
ServerName localhost:443
ServerAdmin you@127.0.0.1
ErrorLog "E:/Program Files/AMPPS/apache/logs/ssl_error.log"
TransferLog "E:/Program Files/AMPPS/apache/logs/ssl_access.log"
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "E:/Program Files/AMPPS/apache/conf/ssl_crt/server.crt"
#SSLCertificateFile "E:/Program Files/AMPPS/apache/conf/server-dsa.crt"
SSLCertificateKeyFile "E:/Program Files/AMPPS/apache/conf/ssl_key/server.key"
<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
</FilesMatch>
<Directory "E:/Program Files/AMPPS/www/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>
BrowserMatch ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0
CustomLog "E:/Program Files/AMPPS/apache/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>
</IfModule>

如果您希望其他域(例如project_one.localhost)具有安全的http连接,则在httpd.conf或httpd-vhosts.conf中添加以下虚拟主机(必须包含在httpd.conf中)

<IfModule ssl_module>

<VirtualHost 127.0.0.1:443>
<Directory "e:/program files/ampps/www/project_one.localhost">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName project_one.localhost
ServerAlias project_one.localhost
ScriptAlias /cgi-bin/ "e:/program files/ampps/www/project_one.localhost/cgi-bin/"
DocumentRoot "e:/program files/ampps/www/project_one.localhost"
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "E:\Program Files\AMPPS/apache/conf/ssl_crt/project_one.localhost.crt"
SSLCertificateKeyFile "E:\Program Files\AMPPS/apache/conf/ssl_key/project_one.localhost.key"
ErrorLog "E:/Program Files/AMPPS/apache/logs/project_one.localhost_ssl_error.log"
TransferLog "E:/Program Files/AMPPS/apache/logs/project_one.localhost_ssl_access.log"
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "e:/program files/ampps/www/project_one.localhost/cgi-bin/">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0
CustomLog "E:/Program Files/AMPPS/apache/logs/project_one.localhost_ssl_request.log" \
    "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
</IfModule>

注意:您将必须在主机文件127.0.0.1 project_one.localhost中添加一个条目

转载请注明:XAMPP中文组官网 » apache-如何在使用虚拟主机时在XAMPP中添加https[SSL证书]

您必须 登录 才能发表评论!