Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
736 views
in Technique[技术] by (71.8m points)

apache - How do I use https (SSL) in XAMPP while using virtual hosts

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:Usersuser_nameDocumentsproject_one"
        ServerName project_one.localhost
        SSLEngine on
        SSLCertificateFile "conf/ssl.crt/server.crt"
        SSLCertificateKeyFile "conf/ssl.key/server.key"
        <Directory "C:Usersuser_nameDocumentsproject_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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:xampphtdocs"
    ServerName localhost
</VirtualHost>
<VirtualHost *:443>
    DocumentRoot "C:Usersuser_nameDocumentsproject_one"
    ServerName project_one.localhost
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    <Directory "C:Usersuser_nameDocumentsproject_one">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "C:Usersuser_nameDocumentsproject_two"
    ServerName project_two.localhost
    <Directory "C:Usersuser_nameDocumentsproject_two">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...