加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

virtualhost – 无法在我的Linux服务器上运行主机文件

发布时间:2020-12-14 02:43:58 所属栏目:Linux 来源:网络整理
导读:我在VirtualBox上运行了Ubuntu 11.10,并且我已经设置了一个虚拟命名服务器. 我可以从 Windows 7访问此站点,但我无法从Ubuntu访问该站点. 我的HOSTS文件位于/ etc /文件夹中,如下所示: 127.0.0.1 localhost127.0.1.1 ubuntu-VirtualBox192.168.0.97 mysite.c
我在VirtualBox上运行了Ubuntu 11.10,并且我已经设置了一个虚拟命名服务器.
我可以从 Windows 7访问此站点,但我无法从Ubuntu访问该站点.

我的HOSTS文件位于/ etc /文件夹中,如下所示:

127.0.0.1       localhost
127.0.1.1       ubuntu-VirtualBox
192.168.0.97     mysite.com

但每当我尝试从服务器访问mysite.com时,我都会被重定向到一个网站,说这个域名是出售的.

什么原因导致主机文件无法正常工作?

更新

这是我的/etc/nsswitch.conf

# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed,try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat

#hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
hosts:          files dns
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

解决方法

首先,检查nsswitch.conf是否正确:
$grep hosts /etc/nsswitch.conf
hosts:          files dns

确保它显示“files dns”,否则在询问DNS之前它不会查看您的hosts文件.

如果在nsswitch中它是正确的,我之前看到一个看不见的角色以某种方式进入我的主机文件,导致它看起来完全正常,但是这个看不见的角色使它不起作用.
因此,尝试删除该行,然后再次创建它 – 手动,不要粘贴.

接下来你可以尝试通过ping来测试它的内容:

$ping mysite.com
PING mysite.com (192.168.0.97) 56(84) bytes of data.

如果您在那里看到正确的IP地址,它确实可以正确解析,并且您的浏览器是导致问题的浏览器.不要使用host,dig或nslookup,它们会忽略/ etc / hosts!使用ping可以解析IP地址,因为大多数应用程序都会看到它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读