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

后端 未结 4 1595
清酒与你
清酒与你 2020-12-02 05:45

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 t

相关标签:
4条回答
  • 2020-12-02 06:19

    Which version of Apache are you using ? NameVirtualHost is not available in 2.4 version.

    Uncomment the line Include conf/extra/httpd-ssl.conf in httpd.conf and add the following contents (fix the paths according to xampp's path). This will enable 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>
    

    If you want other domain like project_one.localhost have secured http connection then add the following virtualhost in httpd.conf or httpd-vhosts.conf(must be included in 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>
    

    Note : You will have to add an entry in hosts file 127.0.0.1 project_one.localhost

    0 讨论(0)
  • 2020-12-02 06:21

    This may be an old question, but i am putting my answer here anyway for future reference

    i'm Using XAMPP 3.2.1, Compiled May,7 2013

    to enable VirtualHost with SSL at the same time here is what i did. (I'm using windows 7)

    1. your windows HOST file must already be setup
    2. Go to httpd-ssl.conf located at xampp\apache\conf\extra

    I just copied the _default_ virtualhost and added my config. I removed all comments for shorter one and pasted this just below the default virtualHost just change the DocumentRoot and servername then Restart 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>
    
    0 讨论(0)
  • 2020-12-02 06:22

    Here is simple step.

    1. Go to C:\xampp\apache\conf

    Open httpd.conf

    And enable the ssl extensions (Remove # from line)

    LoadModule ssl_module modules/mod_ssl.so

    1. Go to C:\xampp\apache\conf\extra

    Open httpd-vhosts.conf

    Add new virtual hosts or edit existing

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

    0 讨论(0)
  • 2020-12-02 06:28

    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>
    
    0 讨论(0)
提交回复
热议问题