search

Home  >  Q&A  >  body text

node.js - 指定域名,无法访问本地node项目(配置server.js端口为3333) 开发工具:webstorm


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

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

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

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

天蓬老师天蓬老师2778 days ago950

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 15:56:54

    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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 15:56:54

    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

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 15:56:54

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

    reply
    0
  • Cancelreply