如何在mac上测试我的localhost上的子域?

时间:2016-08-11 20:06:28

标签: macos dns subdomain

我已经设置了一个Web应用程序,我正在我的localhost上运行它。那是 - http://127.0.0.1:8000/。我也设置了子域名。例如,转到http://blog.127.0.0.1:8000/应该转到博客部分。但是,我的浏览器无法识别这一点,并说服务器无法找到。我的操作系统是MACOSx

  

如果您要在本地主机上测试子域,则需要浏览器将多个子域解析为' 127.0.0.1'。你这样做的方式取决于你的操作系统。如果你正在使用linux,你可以编辑/ etc / hosts。

我从其他用户那里获得了这些信息,但是,我不知道如何在我的Mac上执行此操作。任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:10)

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

127.0.0.1 example.com blog.example.com

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

答案 1 :(得分:0)

必须 添加到文件/etc/hosts

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

Vim编辑器示例 (有关Vim工作的小概述)

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

    sudo vim /etc/hosts
    
  2. 在Vim中,按键盘按钮 i 进入编辑模式

  3. 添加此行:

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

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

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

    • 的行。

就这样,blog.localhostblog.lvh.me已经对您正在使用的所有端口可用。