【问题标题】:How to run a nodejs server on port xxxx and access it through another port?如何在端口 xxxx 上运行 nodejs 服务器并通过另一个端口访问它?
【发布时间】:2018-03-05 21:58:38
【问题描述】:

我正在使用 centOS,我想将端口 xxxx 重定向到 anthor 端口。

node.js 已安装。 我已经用这个笔记试过了: Best practices when running Node.js with port 80 (Ubuntu / Linode)

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

我收到一条错误消息: can't initialize iptables table `nat': 表不存在(需要insmod吗?)

如果有其他方法可以重定向端口,请告诉我。

【问题讨论】:

    标签: routing iptables


    【解决方案1】:

    您可能希望使用 Nginx 作为反向代理。查看 DigitalOcean 的 excellent tutorial 在生产环境中设置 Node.js,它展示了如何以您尝试实现的方式使用 Nginx。即:

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-09-16
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-07
      • 1970-01-01
      • 1970-01-01
      • 2018-07-24
      相关资源
      最近更新 更多