如何在 mac 上测试本地主机上的子域?

How to test sub-domains on my localhost on a mac?

我已经在我的本地主机上 运行 上设置了一个 Web 应用程序。那就是 - http://127.0.0.1:8000/. I have set up sub-domains as well. For example, going to http://blog.127.0.0.1:8000/ 应该带我到博客部分。但是,我的浏览器无法识别并显示找不到服务器。我的 OS 是 MACOSx

If you want to test subdomains on your local host, you need your browser to resolve multiple subdomains as '127.0.0.1'. The way you do this depends on your OS. If you're using linux, you would edit /etc/hosts.

我从另一个用户那里得到了一些信息,但是,我不知道如何在我的 Mac 上执行此操作。感谢任何帮助。

编辑文件 /etc/hosts,添加以下行:

127.0.0.1 example.com blog.example.com

然后试试http://example.com:8000/ and http://blog.example.com:8000/

必须添加到文件/etc/hosts:

127.0.0.1       localhost blog.localhost lvh.me blog.lvh.me

Vim 编辑器示例(关于在 Vim 中工作的小概述)

  1. 运行 编辑文件 /etc/hosts:

     sudo vi /etc/hosts
    
  2. 在Vim中按下键盘按钮i打开编辑模式

  3. 添加这一行:

     127.0.0.1       localhost blog.localhost lvh.me blog.lvh.me
    
  4. 保存文件:

  • 按下按钮 Esc 然后同时按下按钮 shift :

  • 现在您将看到写入 x 并按 Enter

    的行

就这些,localhostblog.localhostlvh.meblog.lvh.me 已经可用于 所有端口使用。