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

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

问题描述

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

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

  1. 创建了 SSL 证书.我按照本教程的第一部分来创建证书.
  2. 我将 server.crt 文件导入到 chrome 中.
  3. 删除了 php.ini;extension=php_openssl.dll 前面的分号 (参考)
  4. 根据 这个 页面.该文件的相关部分如下.这是完整的文件:http://pastebin.com/k6Jh2eR6<块引用>

    DocumentRoot "C:\Users\user_name\Documents\project_one"服务器名称 project_one.localhostSSL引擎开启SSLCertificateFile "conf/ssl.crt/server.crt"SSLCertificateKeyFile "conf/ssl.key/server.key"<目录C:\Users\user_name\Documents\project_one">允许覆盖所有命令允许,拒绝所有人都允许</目录></虚拟主机>

我通常会通过输入http://project_one.localhost

来访问我的项目

尝试通过在 chrome 中输入 https://project_one.localhost 来访问我的项目时,我会自动转发到 https://project_one.localhost/xampp/(好像 XAMPP 根本不将 https://project_one.localhost 识别为子域,并将其视为我正在输入 https://localhost>) 知道我在哪里搞砸了吗?

注意:

  • LoadModule ssl_module modules/mod_ssl.sohttpd.conf 文件中被取消注释

解决方案

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

一个典型的启用 SSL 的 VirtualHost 看起来像这样并且至少包含这些部分...

DocumentRoot "C:/WampDeveloper/Websites/www.example.com/webroot"服务器名称 www.example.comServerAlias example.comSSL引擎开启SSLCertificateFile "C:/WampDeveloper/Websites/www.example.com/certs/public.crt"SSLCertificateKeyFile "C:/WampDeveloper/Websites/www.example.com/certs/private.key"<目录C:/WampDeveloper/Websites/www.example.com/webroot">选项 全部允许覆盖所有命令允许,拒绝允许所有人</目录></虚拟主机>

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

您的 线路有问题.它需要一个端口号,对于 HTTPS://URL,端口号始终为 443,并结合 IP 地址或前面的星号.如果使用星号,还有 NameVirtualHost *:443 行...

NameVirtualHost *:80名称虚拟主机 *:443<虚拟主机 *:80>DocumentRoot "C:\xampp\htdocs"服务器名称本地主机</虚拟主机><虚拟主机 *:443>DocumentRoot "C:\Users\user_name\Documents\project_one"服务器名称 project_one.localhostSSL引擎开启SSLCertificateFile "conf/ssl.crt/server.crt"SSLCertificateKeyFile "conf/ssl.key/server.key"<目录C:\Users\user_name\Documents\project_one">允许覆盖所有命令允许,拒绝所有人都允许</目录></虚拟主机><虚拟主机 *:80>DocumentRoot "C:\Users\user_name\Documents\project_two"服务器名称 project_two.localhost<目录C:\Users\user_name\Documents\project_two">允许覆盖所有命令允许,拒绝所有人都允许</目录></虚拟主机>

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>
    

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天全站免登陆