本文介绍了为开发环境分配一个域名到localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站,不想将网站从指向 http://127.0.0.1 重新配置为 http://www.example.com.此外,我使用的证书当然是使用正确的域名 www.example.com 但我的测试环境调用 127.0.0.1 这使得安全性无法正常工作.

I am building a website and would not like to reconfigure the website from pointing to http://127.0.0.1 to http://www.example.com. Furthermore, the certificate that I am using is of course made with the proper domain name of www.example.com but my test environment makes calls to 127.0.0.1 which makes the security not work properly.

我目前要做的是配置我的开发环境,将域名www.example.com分配给127.0.0.1,这样所有的http://www.example.com/xyz 被路由到 http://127.0.0.1:8000/xyzhttps://www.example.com/xyz 被路由到 https://127.0.0.1:8080/xyz.

What I currently want to do is configure my development environment to assign the domain name www.example.com to 127.0.0.1 so that all http://www.example.com/xyz is routed to http://127.0.0.1:8000/xyz and https://www.example.com/xyz is routed to https://127.0.0.1:8080/xyz.

使用 Apache.我目前使用 node.js 作为我的 Web 服务器,我的开发环境是在 Mac OS X Lion 中.

I am not using Apache. I am currently using node.js as my web server and my development environment is in Mac OS X Lion.

推荐答案

如果你编辑你的 etc/hosts 文件,你可以指定一个任意的主机名来设置为 127.0.0.1.在您喜欢的文本编辑器中打开/etc/hosts 并添加以下行:

If you edit your etc/hosts file you can assign an arbitrary host name to be set to 127.0.0.1.Open up /etc/hosts in your favorite text editor and add this line:

127.0.0.1   www.example.com

不确定如何避免在您向 example.com 发出的 HTTP 请求中指定端口,但如果您必须避免在请求级别指定该端口,您可以以 root 身份运行 nodejs 以使其侦听端口 80.

Unsure of how to avoid specifying the port in the HTTP requests you make to example.com, but if you must avoid specifying that at the request level, you could run nodejs as root to make it listen on port 80.

编辑/etc/hosts 后,您可能已经缓存了该域的 DNS 请求.您可以通过在命令行上运行它来清除缓存的条目.

After editing /etc/hosts, you may already have the DNS request for that domain cached. You can clear the cached entry by running this on the command line.

dscacheutil -flushcache

这篇关于为开发环境分配一个域名到localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-18 13:08