在具有node.js的Mac OS X上为开发环境分配域名到localhost [英] Assigning a domain name to localhost for development environment on Mac OS X with node.js

查看:113
本文介绍了在具有node.js的Mac OS X上为开发环境分配域名到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/xyz https:// 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用户身份运行nodej以使其在端口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

这篇关于在具有node.js的Mac OS X上为开发环境分配域名到localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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