如何在端口xxxx上运行nodejs服务器并通过另一个端口访问它?

问题描述 投票:-1回答:1

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

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

我收到一条错误消息:无法初始化iptables表`nat':表不存在(你需要insmod吗?)

如果有另一种方法来重定向端口请告诉我。

routing iptables
1个回答
0
投票

您可能希望将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;
}
© www.soinside.com 2019 - 2024. All rights reserved.