Вопрос

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.

Это было полезно?

Решение

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.

Другие советы

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>

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>

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!

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>

I use my own domains (ended with .lc) for development web application on localhost. I will describe simple solution for dynamic .lc domains and development enviroment that works without dependency on internet connection.

I wrote about it on my blog too: http://www.michalseidler.com/development/localhost-development-enviromet-for-php/

For this example i try describe configuration of local dynamic domains *.lc with Wamp Server. I have my projects stored in C:\wamp\www\projects\projectname\ and i use dynamic maping projectname.lc. This means that i can access every project directory with domain [project direktory name].lc

Step 1 – configuration of local WAMP server

First of all you need place configuration of *.lc domain into httpd.conf:

<VirtualHost 127.0.0.1>
ServerName lc
ServerAlias *.lc
DocumentRoot "C:\wamp\www\projects"
</VirtualHost>;

You need insert .htaccess file into projects direktory (in my example into: C:\wamp\www\projects) this configuration maps *.ls domains to project direktories. Ex.: If you have sources in direktory ‚myapp‘ you can use www.myapp.lc to open it in browser.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]*)\.([^\.]*)$
RewriteRule (.*) http://www.%1.%2/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.([^.]+)\.([^\.]*)$ [NC]
RewriteRule ^(.*)$ http://%1.%2.%3/$1 [L,R=301]

RewriteCond %{REQUEST_URI} !^projects/
RewriteCond %{REQUEST_URI} !^/projects/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteRule (.*) %3/$1 [DPI] 

After this changes restart Wamp Server

Step 2 – configuration of local DNS server

Because we can’t use *.lc in Windows host file we need instal local DNS server. I choose Acrylic DNS Server because it is very simple for configuration.

After instalation find AcrylicHosts file (C:\Program Files (x86)\Acrylic DNS Proxy) and insert new line:

127.0.0.1 *.lc

This is only DNS configuration we need so restart Acrylic DNS service.

Step 3 – configuration of network adapter

Final step is install new fake network adapter and assign DNS server: 1.Click the Start menu. 2.Search for “cmd“. 3.Right-click on “cmd” and select “Run as Administrator” 4.Enter “hdwwiz.exe” 5.In the „Welcome to the Add Hardware Wizard“, click Next. 6.Select „Install the hardware that I manually select from a list (Advanced)“ and click Next. 7.Scroll down and select „Network adapters“ and click Next. 8.Select under Manufacturer „Microsoft“ and then under Network Adapter „Microsoft Loopback Adapter“ and click Next.

In next step you must change TCP/IP settings of new created adapter: 1.Log on to the computer by using the Administrator account. 2.Click Start, point to Control Panel, and click Network Connections. 3.Right-click the Loopback connection and then click Properties. 4.In the This connection uses the following items box, click Internet Protocol (TCP/IP), and then click Properties. The Internet Protocol (TCP/IP) Properties dialog box appears.

IP addess: 192.168.1.1
Subnet mask: 255.255.255.0
Default Gateway: empty

Prefered DNS server: 127.0.0.1

Now close all dialogs and its done! You can try open [your project name].lc

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top