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

查看:27
本文介绍了为开发环境分配一个域名给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/xyzhttps://www.example.com/xyz 被路由到 https://127.0.0.1:8080/xyz.

使用 Apache.我目前使用 node.js 作为我的网络服务器,我的开发环境在 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天全站免登陆