Node.js服务器收到错误:侦听 EACCES:在 GoDaddy VPS Linux 服务器中使用端口 80 或 443



js网站,当我使用端口3200和80时,本地系统一切都很好,当我将代码部署到godaddy vps linux服务器时,我收到错误

错误:侦听 EACCES:权限被拒绝 0.0.0.0.80 ###

在 GoDaddy VPS Linux 服务器中使用端口 80 或 443 而不是 3000 时


console.log('Welcome to Node Server... ');
var process = require('process');
var http = require('http');
var https = require('https');
var url = require('url');

const mysql = require('mysql');
const express = require('express');
// var router = express.Router();
const app = express();
const bodyParser = require('body-parser');
const path = require('path');
const fs = require('fs');
const multer = require('multer');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var connection = require('./db.js');
const cors = require('cors');
// app.use(cors())
// app.use(cors({ origin: "http://localhost:4200", credentials: true }));

app.use((req, res, next) => { res.send('<h1>Hello from HowTags!!!</h1>'); });
const options = {
// key: fs.readFileSync('server.key'),
// cert: fs.readFileSync('server.cert'),
cert: fs.readFileSync('./ssl/7f16b8c7268c5ae5.crt'),
// key: fs.readFileSync('./ssl/generated-private-key.txt'),
pem: fs.readFileSync('./ssl/7f16b8c7268c5ae5.pem'),
};

http.createServer(app).listen(80, null, null, () => { console.log('Server started listening on port ' + 80); });
https.createServer(options, app).listen(443, null, null, () => { console.log('Server started listening on port ' + 443); });
// Code Ends ..................................................

我也尝试使用 .htaccess 重定向,但它不起作用

RewriteEngine On
RewriteRule ^$ http://howtags.com:8000 [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ https://howtags.com:443$1 [P,L]
RewriteRule (.*) http://howtags.com:80/$1 [L,P,QSA]   
+++++++++++++++++++++++++
PassengerBaseURI /
PassengerAppRoot /home/howtags/howtags/node
PassengerAppType node
PassengerStartupFile index.js

如果有人发现代码中有任何问题,请告诉我... 如果有人知道更好的解决方案,请告诉我....

我通过使用NGINX找到了解决方案

点击以下链接了解有关NGINX的更多信息

https://www.server-world.info/en/note?os=CentOS_8&p=nginx&f=8

服务器代码

http.createServer(app).listen(3000, () => { console.log('Server started listening on port ' + 3000); });

.htaccess 文件的代码

RewriteEngine On
RewriteRule ^$ http://example.com:3000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://example.com:3000/$1 [P,L]

+++++++++++++++++++++++++
PassengerBaseURI /
PassengerAppRoot /home/example/app/node
PassengerAppType node
PassengerStartupFile index.js

我认为GoDaddy对低于几千个的端口有限制。您将需要 sudo 功能。我在这里发现了一些东西。

最新更新