Using Domain name instead of localhost in with https in xampp

112,419

Solution 1

I tried many things, But I think I missed basic edit.

Now all working fine.

Now host file is still the same as mentioned in question. I did not make any changes to it.

I changed port in httpd-vhosts.config as shows below.

NameVirtualHost *
    <VirtualHost *>
        DocumentRoot "C:/xampp/htdocs"
        ServerName localhost
    </VirtualHost>
    <VirtualHost *>
        ServerName www.mysite.com
        ServerAlias mysite.com
        DocumentRoot "C:/xampp/htdocs/mysite"
    </VirtualHost>

Also the step I missed, was editing httpd-ssl.config file in same folder that of httpd-vhosts.config.

I just added following lines before last line of http-ssl.config file i.e. < /IfModule>

<VirtualHost _default_:443> 
    DocumentRoot "C:/xampp/htdocs/mysite" 
    ServerName www.mysite.com:443 
    ServerAlias mysite.com:443  
    SSLEngine on 
    SSLCertificateFile "conf/ssl.crt/server.crt" 
    SSLCertificateKeyFile "conf/ssl.key/server.key" 
</VirtualHost> 

Thank You all friends for helping me lot on this, Without your links I would never ever be able to find out that I need to edit one more file.

Solution 2

Let me explain step by step for other guys too.

1. Map your custom domain name to localhost in HOSTS file.

Open hosts file and add below line.

127.0.0.1 www.example.com

2. Tell XAMPP about your custom domain.

Add below content to httpd-vhosts.conf

<VirtualHost *>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot "C:/xampp/htdocs/example"
</VirtualHost>

If you have port for your localhost, then add it as <VirtualHost *:80>

Restart apache,Now you can access http://example.com in your browser.

3. If you want to access https://example.com

Add below line to httpd-vhosts.conf

<VirtualHost *:443>
    DocumentRoot "C:/xampp/htdocs/example"
    ServerName www.example.com
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    <Directory "C:/xampp/htdocs/example">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Solution 3

I'm not too familiar with apache but perhaps not specifying a port defaults to :80 and adding this would magically fix everything?

<VirtualHost 127.0.0.1:443>
    ServerName www.mysite.com
    ServerAlias mysite.com
    DocumentRoot "C:/xampp/htdocs/mysite"
</VirtualHost>

Solution 4

I have been googling for hours trying to figure out why the newest XAMPP release puts 1200MS on page generation times... I thought it was maybe my code working with some pretty complex class systems yet.. this thread pointed out the whole localhost <> 127.0.0.1

I'm on Windows 7 and I didn't think to use CMD to "ping localhost"

the result was "::1:" not 127.0.0.1

After a quick windows/system32/drivers/etc/host file edit to uncomment out the line

127.0.0.0 localhost

My page times went back to normal. Might be someone else is having this problem recently and seeing as this thread ranks top in Google then good luck!

Solution 5

I started with multiple custom domains. See new code below:

Note: WordPress strips backslashes, so below I’ve replaced them with forward slashes. I believe it with work regardless either way.

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/Users/Austin Passy/Documents/InMotion Hosting/frostywebdev.com/html"
    ServerName frostyweb.dev
    <Directory "C:/Users/Austin Passy/Documents/InMotion Hosting/frostywebdev.com/html">
    Options Indexes FollowSymLinks ExecCGI Includes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/eateryengine"
    ServerName eateryengine.dev
    <Directory "C:/xampp/htdocs/eateryengine">
    Options Indexes FollowSymLinks ExecCGI Includes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
Share:
112,419
Jeet Chaudhari
Author by

Jeet Chaudhari

Updated on July 09, 2022

Comments

  • Jeet Chaudhari
    Jeet Chaudhari almost 2 years

    My question may be stupid, But honestly I searched a lot and got success but not complete.

    I use xampp with windows 8.

    My host file looks as follows.

        127.0.0.1   localhost
        127.0.0.1   www.mysite.com
    

    My httpd-vhosts.config looks as follows.

        NameVirtualHost 127.0.0.1
        <VirtualHost 127.0.0.1>
            DocumentRoot "C:/xampp/htdocs"
            ServerName localhost
        </VirtualHost>
        <VirtualHost 127.0.0.1>
            ServerName www.mysite.com
            ServerAlias mysite.com
            DocumentRoot "C:/xampp/htdocs/mysite"
        </VirtualHost>
    

    This works perfect for http. But I have enabled ssl.

    When I type http://localhost or https://localhost, Both work fine.

    When I type http://mysite.com it works,

    when I type https://mysite.com it is redirected as https://mysite.com/xampp/ and shows me default welcome page of xampp.

    I tried following things.

    1) instead of using 127.0.0.1, I tried using *:80 in httpd-vhosts.conf But result was same.

    2) instead of using 127.0.0.1, I tried using *:443 in httpd-vhosts.conf But at the time of restarting apache fails to start again.

    Please let me know how can I access my site through domain name instead of localhost with https or http.