node.js - 指定域名,无法访问本地node项目(配置server.js端口为3333) 开发工具:webstorm
天蓬老师
天蓬老师 2017-04-17 15:54:54
0
3
948


如上图所示,指定域名为www.aaa.com 如果将server.js的prot值改为80可以正常访问,但80有其他项目在用这个项目想用3333

备注:因项目比较有针对性,本地访问也必须是域名形式才能正常

在网上看到也有类似的需求 如:https://segmentfault.com/q/10...

解决方案是http-proxy 但我安装后还是不太会配置

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
洪涛

The problem has been solved. I develop under windows and use nginx as a reverse proxy

The first step of installation
http://www.cnblogs.com/wenanr... Refer to the introduction of this article (I just started searching the official website to download the latest one directly, but it didn’t work. Later I saw the download link in this article After downloading the settings, it was successful. Note: It may be that I made a mistake in other operations)
The second step is to configure the reverse proxy
Find the nginx.conf file in the conf folder in the nginx directory you installed, and find server{ in the file ……} Start a new line and add the following code:

server{

    listen 80;
    server_name www.test.com;
    location /{
        proxy_pass http://127.0.0.1:3333;
    }
}

You can modify the values ​​of server_name and proxy_pass accordingly
Just restart nginx

伊谢尔伦

It should be ok

Local hosts

127.0.0.1 www.jiangli.com

You mean to access www.aaa.com directly to access your project, but the port of your project is 3333, so you can only use nginx to create a reverse proxy

When the port of your project is 80, the reason why you can access it through www.aaa.com is because the default requests are all port 80

www.aaa.com and www.aaa.com:80 are equivalent

左手右手慢动作

Either add the port number after the address, or use nginx or the like as a proxy

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template