大网数据广告活动
网站运营与故障问答

Test website can't be reached despite setting up DNS in local hosts file and adding a virtual host to Apache config

· 52CE 我爱测

I am trying to set up a domain on my development machine so that I cant test slightly more complex htaccess rules. I am trying to set up example.city domain. Following what I find by googling, I have done the following: Windows h…

问题原文

原帖链接 · Rohit Gupta · CC BY-SA 4.0

I am trying to set up a domain on my development machine so that I cant test slightly more complex htaccess rules. I am trying to set up example.city domain. Following what I find by googling, I have done the following:

Windows hosts file Windows/System32/drivers/etc

127.0.0.1   example.city
127.0.0.1   www.example.city
127.0.0.1   localhost

And I have flushed the DNS cache more than 20 times by now by using

ipconfig /flushdns

When I ping example.city, I get the following, so I am confident that this part is fine.

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Next I set up the httpd-vhosts/conf file in xampp/apache/conf/extra

<VirtualHost *:80>
  ServerAdmin [email omitted]
  DocumentRoot "F:/xampp/htdocs/city"
  ServerName example.city
  ServerAlias *.example.city
  ErrorLog "logs/example.city-error.log"
  CustomLog "logs/example.city-access.log" common
  <Directory />
    Options FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerAdmin [email omitted]
  DocumentRoot "F:/xampp/htdocs"
  ServerName localhost
  ServerAlias *.localhost
</VirtualHost>

I stopped and started apache.

When I type in localhost/city in the browser it executes the html there.

I have flushed the browser cache and tried 2 different browsers. When I type in example.city or http://example.city, I get the following

This site can’t be reached

The webpage at http://example.city/ might be temporarily down or it may have moved permanently to a new web address.

  • ERR_ADDRESS_INVALID

The two error logs files got created but are blank.

Am I not allowed to do this? Or have I missed a step?

已采纳解答

原帖链接 · Stephen Ostermiller · CC BY-SA 4.0

The browser that you are using to test likely has DNS over HTTPS (DoH) enabled. That is a feature where the browser ignores the local DNS settings and instead looks up DNS from its own internet provider. This causes your browser to ignore any DNS overrides made through your local hosts file. The solution is going to be to disable this browser feature in all the browsers with which you are testing.

Chrome

Open chrome://settings/security and turn off "Use secure DNS."

After changing this setting you may also have to clear your cache from chrome://settings/clearBrowserData by choosing to "Clear browsing data" for "All time" and choosing "Cached images and Files"

Firefox

Go into the menu then "settings" then "general", and scroll to "Network Settings" and click "Settings..." Scroll down to "Enable DNS over HTTPS" and uncheck the box. (source)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2022-02-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。