为开发环境分配域名到localhost [英] Assigning a domain name to localhost for development environment

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

问题描述

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

我当前要做的是配置我的开发环境,以将域名www.example.com分配给127.0.0.1,以便将所有http://www.example.com/xyz路由到http://127.0.0.1:8000/xyz,而将https://www.example.com/xyz路由到https://127.0.0.1:8080/xyz. /p>

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

解决方案

如果您编辑etc/hosts文件,则可以分配任意主机名以将其设置为127.0.0.1. 在您喜欢的文本编辑器中打开/etc/hosts并添加以下行:

127.0.0.1   www.example.com

不确定如何避免在对example.com的HTTP请求中指定端口,但是如果必须避免在请求级别指定端口,则可以以root用户身份运行nodejs使其在端口80上侦听.

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

dscacheutil -flushcache

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.

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.

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.

解决方案

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

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.

Edit: 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆