如何在使用虚拟主机时在XAMPP中使用https(SSL)

时间:2013-05-08 00:04:51

标签: apache ssl https xampp virtualhost

我正在本地计算机上编写一个php应用程序,并希望测试SSL是否正常工作。请耐心等待,因为这是我第一次使用SSL。

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

  1. 创建了SSL证书。我按照这个this教程的第一部分来创建证书。
  2. 我将server.crt文件导入了chrome。
  3. 删除;extension=php_openssl.dll php.inihttpd-vhosts.conf前面的分号(reference
  4. 根据this页面修改了我的<VirtualHost *> 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> 文件。该文件的相关部分如下。这是完整档案:http://pastebin.com/k6Jh2eR6
    http://project_one.localhost
  5. 我通常会输入https://project_one.localhost

    来访问我的项目

    尝试通过在Chrome中输入https://project_one.localhost/xampp/来访问我的项目时,我会自动转发到https://project_one.localhost(就好像XAMPP根本不会将https://localhost识别为子域名一样把它看成是我输入的LoadModule ssl_module modules/mod_ssl.so)我知道我搞砸了什么?

    注:

    • httpd.conf已在{{1}}档案
    • 中取消注释

4 个答案:

答案 0 :(得分:39)

HTTPS://url.here/种类的SSL完全由Apache处理,与PHP,PHP的任何扩展/模块或任何php.ini设置无关。

典型的SSL Enabled 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>

答案 1 :(得分:7)

这可能是一个老问题,但无论如何我都会在这里提出答案以供将来参考

使用XAMPP 3.2.1,2013年5月7日编译

同时启用VirtualHost SSL这就是我所做的。 (我使用的是Windows 7)

  1. 您的Windows HOST文件必须已设置
  2. 转到位于httpd-ssl.conf
  3. 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>
    

答案 2 :(得分:6)

这是一个简单的步骤。

  1. 转到 C:\ xampp \ apache \ conf
  2. 打开 httpd.conf

    启用 ssl扩展程序从行中移除#

    &#13;
    &#13;
    LoadModule ssl_module modules/mod_ssl.so
    &#13;
    &#13;
    &#13;

    1. 转到 C:\ xampp \ apache \ conf \ extra
    2. 打开 httpd-vhosts.conf

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

      &#13;
      &#13;
      <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>
      &#13;
      &#13;
      &#13;

答案 3 :(得分:3)

您使用的是哪个版本的Apache? NameVirtualHost在2.4版本中不可用。

取消注释httpd.conf中的行Include conf/extra/httpd-ssl.conf并添加以下内容(根据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