Tôi đang tạo một máy chủ HTTPS lần đầu tiên trong Node và mã (xem bên dưới) hoạt động cho một cổng ngẫu nhiên như 6643 nhưng trên cổng 443, nó sẽ không hoạt động. Tôi gặp lỗi này:Máy chủ https của Node.js: Không thể nghe cổng 443 - Tại sao?
[Debug][Server]: Initialized...
[Debug][Control Center]: Application initialized...
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EACCES
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1023:19)
at listen (net.js:1064:10)
at Server.listen (net.js:1138:5)
at Object.module.exports.router (/home/ec2-user/Officeball/Versions/officeball_v0.0.5/server/custom_modules/server.js:52:5)
at Object.<anonymous> (/home/ec2-user/Officeball/Versions/officeball_v0.0.5/server/control_center.js:15:59)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Đây là máy chủ Amazon Linux EC2. Đó là sự hiểu biết của tôi rằng khi tôi đặt DNS A Name Record của miền của mình thành IP của máy chủ, khi người dùng tìm kiếm https://mydomain.com, trình duyệt sẽ tra cứu IP của máy chủ của tôi tại cổng 443, được cho là cổng chuẩn cho lưu lượng HTTPS.
Vì vậy, hiểu biết của tôi là tôi cần phải phục vụ https nội dung qua cổng 443.
Tôi đang làm gì sai?
Đây là mã máy chủ của tôi:
control_center.js (init)
/* Control Center */
//DEFINE GLOBALS
preloaded = {};
//GET DIRECT WORKING PATH
var dirPath = process.cwd();
//REQUIRE CUSTOM MODULES
var debug = new (require(dirPath +
"/custom_modules/debug"))("Control Center");
var socket = require(dirPath +
"/custom_modules/socket")(4546);
// ! this is the relevant line
var server = require(dirPath + "/custom_modules/server").router(443);
//APP INITIALIZE
debug.log("Application initialized...");
server.js
/* Server */
//REQUIRE NPM MODULES
var fs = require('fs'),
https = require('https'),
url = require('url'),
path = require('path');
//GET DIRECT WORKING PATH
var dirPath = process.cwd();
//REQUIRE CUSTOM MODULES
//Snip!
var debug = new (require(dirPath +
"/custom_modules/debug"))("Server");
//Preload requests
var preload = require(dirPath +
'/custom_modules/preload').init();
//INIT MODULE
debug.log("Initialized...");
//DEFINE MODULE VARIABLES
var options = {
key: fs.readFileSync('SSL/evisiion_private_key.pem'),
cert: fs.readFileSync('SSL/evisiion_ssl_cert.pem')
};
//LISTEN FOR PATH REQUESTS
//route requests to server
module.exports.router = function(port) {
https.createServer(options, function(req, res) {
//Snip!
}).listen(port);
};
Có lẽ không phải là mã, hãy xem [ở đây] (http://stackoverflow.com/questions/5004159/opening-port-80-ec2-amazon-web-services/10454688#10454688). –
@BrendanAshworth khi nó đơn giản đến nỗi đau ... –
lý do duy nhất tôi biết là bởi vì tôi đã trả lời cùng một câu hỏi trước :) cũng có thể phải làm với người dùng root riêng nếu câu trả lời không sửa chữa nó –