在localhost中使用域名

时间:2015-12-03 09:37:42

标签: php apache localhost

我在localhost中使用域名时遇到问题 我在windows 8.1 64 bit

中使用drive F和我的xampp

我已在httpd.conf编辑F:\xampp\apache\conf以加载vhost

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

已在httpd-vhosts.conf

中编辑F:\xampp\apache\conf\extra
NameVirtualHost *:80
<VirtualHost *:80>
   DocumentRoot "F:/xampp/htdocs/itklan/public/"
   ServerName mydomain.dev
   ServerAlias mydomain.dev
     <Directory "F:/xampp/htdocs/itklan/public/">
        Order allow,deny
        Allow from all
     </Directory>
</VirtualHost>

我在host

中添加C:\Windows\System32\drivers\etc
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost
    127.0.0.1       mydomain.com

已经重新启动apache ...我甚至重启我的窗口

但我仍然在谷歌浏览器中得到类似的内容

This webpage is not available
ERR_CONNECTION_REFUSED
我失踪了吗? ps:我仍然可以正常访问http://localhost:8080/itklan/public/

更新

当我尝试ping mydomain.dev时,它成功从我的localhost ip接收所有数据

enter image description here

我测试运行127.0.0.1它正在显示

This webpage is not available
ERR_CONNECTION_REFUSED

of cource,因为我将我的apache端口更改为8080,将mysql端口更改为4433
所以它应该是127.0.0.1:8080来打开xampp主页

基于this页面 - &gt; 感谢abdula
我尝试编辑'httpd-vhosts.conf'并使其监听端口8080
但是当我添加脚本Listen 8080时,我的阿帕奇不会再次运行了 我试图将该脚本更改为Listen 80,这样我的apache就可以再次运行了。我注意到apache开放端口现在变为3 (80, 8080, 4433) 所以我想我不需要再次添加Listen 8080因为我的apache已经听过那个端口了 所以我就像这样改变了其余的

NameVirtualHost *:8080
<VirtualHost *:8080>
   DocumentRoot "F:/xampp/htdocs/itklan/public/"
   ServerName mydomain.dev
</VirtualHost>

并在hosts file

# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost
    127.0.0.1  mydomain.dev

但它仍然相同

1 个答案:

答案 0 :(得分:0)

  
    
      

请勿使用 .com 域名。使用 .dev 或不可用的内容

    
  

并尝试此主机

<VirtualHost mydomain.dev>    
    DocumentRoot F:/xampp/htdocs/itklan/public/  
    ServerName mydomain.dev
    ServerAlias server  
</VirtualHost> 

VirtualHost Examples

编辑01

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot F:/xampp/htdocs/itklan/public/  
ServerName mydomain.dev
</VirtualHost>