在xampp中使用https使用域名而不是本地主机


Using Domain name instead of localhost in with https in xampp

我的问题可能是愚蠢的,但老实说,我搜索了很多,得到了成功,但不完整。

我在windows 8中使用xampp。

我的主机文件如下所示。

    127.0.0.1   localhost
    127.0.0.1   www.mysite.com
我httpd-vhosts

。配置如下:

    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>

这适用于http。但是我已经启用了ssl。

当我输入http://localhosthttps://localhost时,两者都可以正常工作。

当我输入http://mysite.com它工作,

当我输入https://mysite.com时,它被重定向为https://mysite.com/xampp/,并显示xampp的默认欢迎页面。

我试着做以下事情。

1),而不是使用127.0.0.1,我尝试使用*:80在httpd-vhosts.conf,但结果是一样的。

2)我尝试在httpd-vhosts.conf中使用*:443,而不是使用127.0.0.1,但是在重新启动apache时失败了。

请让我知道如何通过域名访问我的网站,而不是使用https或http的localhost。

我尝试了很多东西,但我想我错过了基本的编辑。

现在一切正常

现在主机文件仍然是相同的问题中提到的。我没有对它做任何修改。

我改变了httpd-vhosts的端口。配置如下:

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

我还错过了编辑httpd-ssl的步骤。httpd-vhosts.config.

我只是在http-ssl的最后一行之前添加了以下几行。配置文件,即

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

谢谢所有的朋友帮助我很多在这方面,没有你的链接,我将永远无法发现,我需要编辑一个文件。

让我一步一步地解释给其他人听。

1。

将您的自定义域名映射到HOSTS文件中的localhost。

通常在哪里找到hosts文件:

  • Unix (Linux,Mac): /etc/hosts .
  • Windows: C:'Windows'System32'drivers'etc'hosts

打开hosts文件,并添加以下行

127.0.0.1 www.example.com

2。告诉XAMPP您的自定义域名。

将以下内容添加到httpd-vhosts.conf

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

如果您的本地主机有端口,那么将其添加为 <VirtualHost *:80>

重新启动apache,现在您可以在浏览器中访问http://example.com。


3。如果您想访问https://example.com

添加以下一行到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>

我已经在谷歌上搜索了几个小时,试图弄清楚为什么最新的XAMPP版本在页面生成时间上花费了1200MS…我想这可能是我的代码与一些相当复杂的类系统工作。这个线程指出了整个localhost <> 127.0.0.1

我在Windows 7上,我没有想到使用CMD来"ping localhost"

结果是"::1:"而不是127.0.0.1

在快速编辑windows/system32/drivers/etc/host文件后取消注释行

127.0.0.0 localhost

我的页面时间恢复正常。可能是其他人最近有这个问题,看到这个帖子在谷歌排名第一,那么祝你好运!

我从多个自定义域开始。见下面的新代码:

注意:WordPress去掉了反斜杠,所以下面我用正斜杠代替了它们。不管怎样,我都相信这是工作。

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

我不太熟悉apache,但也许不指定端口默认值为:80,并添加这将神奇地修复一切?

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

我使用自己的域名(以。lc结尾)在本地主机上开发web应用程序。我将描述动态。lc域和开发环境的简单解决方案,不依赖于互联网连接。

我也在我的博客上写过:http://www.michalseidler.com/development/localhost-development-enviromet-for-php/

在这个例子中,我尝试描述本地动态域*的配置。lc与Wamp服务器。我有我的项目存储在C:'wamp'www'projects'projectname'和我使用动态映射projectname.lc。这意味着我可以访问域为[项目目录名].lc

的每个项目目录。

步骤1 -配置本地WAMP服务器

首先你需要*的位置配置。导入httpd.conf:

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

你需要将。htaccess文件插入到projects目录(在我的例子中插入到:C:'wamp'www'projects),这个配置映射到*。Ls域到项目目录。例如:如果你有资源目录,myapp ',你可以使用www.myapp.lc在浏览器中打开它。

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] 

修改后重启Wamp服务器

步骤2 -配置本地DNS服务器

因为我们不能用*。我们需要在Windows主机文件中安装本地DNS服务器。我选择丙烯酸DNS服务器,因为它是非常简单的配置。

安装后找到AcrylicHosts文件(C:'Program Files (x86)'Acrylic DNS Proxy)并插入新行:

127.0.0.1 *.lc

这只是我们需要的DNS配置,所以重新启动丙烯酸DNS服务。

步骤3 -配置网卡

最后一步是安装新的假网卡并分配DNS服务器:1.单击开始菜单。2.搜索"cmd"。3.右键单击"cmd",选择"以管理员身份运行"4.输入"hdwwiz.exe"5.在"欢迎进入添加硬件向导"中,单击"下一步"。6.选择"Install the hardware that I manually Select from a list (Advanced)",然后单击Next。7.向下滚动并选择"Network adapters",然后单击Next。8.在"制造商"下选择"Microsoft",然后在"网络适配器"下选择"Microsoft环回适配器",然后单击下一步。

在下一步中,您必须更改新创建适配器的TCP/IP设置:1.使用Administrator帐户登录计算机。2.单击开始,指向控制面板,然后单击网络连接。3.右键单击环回连接,然后单击属性。4.在"此连接使用以下项目"框中,单击"Internet协议(TCP/IP)",然后单击"属性"。弹出"Internet协议(TCP/IP)属性"对话框。

IP addess: 192.168.1.1
Subnet mask: 255.255.255.0
Default Gateway: empty
Prefered DNS server: 127.0.0.1

现在关闭所有对话框,完成!你可以试着打开[你的项目名].lc