【问题标题】:Remove port 3000 for nodejs in nginx在 nginx 中删除 nodejs 的端口 3000
【发布时间】:2017-08-16 23:35:25
【问题描述】:

我花了 1 天时间在 google 上搜索所有代码并尝试了所有代码,但似乎没有任何效果。 我的服务器代码。

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

我尝试将 3000 替换为 80 但不起作用。

我也尝试在 etc/nginx/conf/example.com.cof 中进行更改

server {
    listen   80;
    upstream project {
    server example.com:3000;
}

server {
  listen 80;

  location / {
    proxy_pass http://project;
   }

    server_name example.com;
    rewrite ^(.*) http://example.com$1 permanent;
  }

server {
    listen   80 default_server;

     ...
    }

没有任何作用。

请帮忙

【问题讨论】:

  • 请修正代码格式。太难读了,更不用说语法不正确
  • 一些端口是为系统服务和守护进程保留的。例如,80 端口是为 Linux 中的 http 服务保留的。最好不要更改此端口。 Here 是 Linux 中所有保留端口的列表。避免将这些端口用于您的应用程序。
  • 还是不正确

标签: node.js express nginx port


【解决方案1】:

使用 80 端口需要 sudo 权限

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

使用启动应用程序,

sudo PORT=80 node app.js
sudo PORT=80 npm start #or like this, depends on your app

【讨论】:

  • 找出哪个进程在使用它lsof -i tcp:3000,并杀死它kill pid
  • 我很困惑。你是告诉我使用端口 80 还是 3000?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-21
  • 2021-09-27
  • 2013-05-19
  • 2020-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多