如何在XAMPP使用HTTPS(SSL),而使用虚拟主机 [英] How do I use https (SSL) in XAMPP while using virtual hosts

查看:2181
本文介绍了如何在XAMPP使用HTTPS(SSL),而使用虚拟主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写我的本地机器上的PHP应用程序,并想测试一下,看看是否SSL是工作。和我一起承担,因为这是我用过SSL的第一次。

到目前为止,这是我做了什么:


  1. 创建一个SSL证书。我跟着这个本教程创建证书。

  2. 我进口 server.crt 文件复制到浏览器。

  3. 中删除前面的分号;延长= php_openssl.dll 的php.ini reference

  4. 基于的编辑我的的httpd-vhosts.conf 文件http://www.leonardaustin.com/technical/how-to-enable-ssl -on-XAMPP-用的虚拟主机>这个页面。该文件的相关部分如下。这是一个完整的文件: http://pastebin.com/k6Jh2eR6


     <虚拟主机* GT;
        的DocumentRootC:\\用户\\用户名\\文档\\ project_one
        服务器名project_one.localhost
        在SSLEngine的
        了SSLCertificateFile的conf / ssl.crt / server.crt
        了SSLCertificateKeyFile的conf / ssl.key / server.key
        <目录C:\\用户\\用户名\\文档\\ project_one>
            所有的AllowOverride
            为了允许,拒绝
            所有允许
        < /目录>
    < /虚拟主机>< /李>


      
      


  我通常会在键入HTTP访问我的项目://project_one.localhost


当试图通过键入 HTTPS访问我的项目://project_one.localhost 进入铬我自动将转发到 HTTPS:/ /project_one.localhost/xampp / (好象XAMPP不承认的https://project_one.localhost 为所有子域并且把它仿佛我打字的的https://本地主机)任何想法,我搞砸了

请注意:


  • 的LoadModule ssl_module模块/ mod_ssl.so 的httpd.conf 被注释掉文件


解决方案

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

已启用虚拟主机典型的SSL看起来像这一点,至少包含以下部分...

 <虚拟主机*:443>
    的DocumentRootC:/WampDeveloper/Websites/www.example.com/webroot
    服务器名www.example.com
    ServerAlias​​ example.com    SSLEngine的在    了SSLCertificateFileC:/WampDeveloper/Websites/www.example.com/certs/public.crt
    了SSLCertificateKeyFileC:/WampDeveloper/Websites/www.example.com/certs/private.key    <目录C:/WampDeveloper/Websites/www.example.com/webroot>
        所有的选项
        所有的AllowOverride
        为了允许,拒绝
        所有允许
    < /目录>< /虚拟主机>

(上面的路径是从我WampDeveloper专业设置,Xampp时的会略有不同)

<虚拟主机* GT; 线出现故障。它需要一个端口号,这始终是443一个HTTPS:// URL,在任一IP地址或之前的明星组合。如果使用的是明星,也有 *了NameVirtualHost:443 行...

 了NameVirtualHost *:80
*了NameVirtualHost:443<虚拟主机*:80>
    的DocumentRootC:\\ XAMPP \\ htdocs中
    服务器名本地主机
< /虚拟主机>
<虚拟主机*:443>
    的DocumentRootC:\\用户\\用户名\\文档\\ project_one
    服务器名project_one.localhost
    在SSLEngine的
    了SSLCertificateFile的conf / ssl.crt / server.crt
    了SSLCertificateKeyFile的conf / ssl.key / server.key
    <目录C:\\用户\\用户名\\文档\\ project_one>
        所有的AllowOverride
        为了允许,拒绝
        所有允许
    < /目录>
< /虚拟主机>
<虚拟主机*:80>
    的DocumentRootC:\\用户\\用户名\\文档\\ project_two
    服务器名project_two.localhost
    <目录C:\\用户\\用户名\\文档\\ project_two>
        所有的AllowOverride
        为了允许,拒绝
        所有允许
    < /目录>
< /虚拟主机>

I am writing a php app on my local machine and would like to test to see if SSL is working. Bear with me because this is the first time I've ever used SSL.

So far this is what I've done:

  1. Created a SSL Certificate. I followed the first part of this this tutorial to create the certificate.
  2. I imported the server.crt file into chrome.
  3. Removed the semicolon in front of ;extension=php_openssl.dll in php.ini (reference)
  4. Edited my httpd-vhosts.conf file based on this page. The relevant section of that file is below. This is the full file: http://pastebin.com/k6Jh2eR6

    <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></li>
    

I would usually access my project by typing in http://project_one.localhost

When trying to access my project by typing https://project_one.localhost into chrome I automatically get forwarded to https://project_one.localhost/xampp/ (as if XAMPP doesn't recognize https://project_one.localhost as a subdomain at all and treats it as if I'm typing in https://localhost) Any idea where I'm screwing up?

NOTE:

  • LoadModule ssl_module modules/mod_ssl.so was uncommented in httpd.conf file

解决方案

SSL, of the HTTPS://url.here/ variety, is entirely handled by Apache and has nothing to do with PHP, or any of PHP's extensions/modules, or any php.ini settings.

A typical SSL Enabled VirtualHost looks like this and contains at least these parts...

<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>

(The paths above are from my WampDeveloper Pro set up, Xampp's will be slightly different)

Your <VirtualHost *> line is faulty. It needs a port number, which is always 443 for an HTTPS:// URL, in combination with either an IP address or a star before it. And if using a star, also a NameVirtualHost *:443 line...

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使用HTTPS(SSL),而使用虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆