错误:侦听EACCES 0.0.0.0:80 OSx Node.js [英] Error: listen EACCES 0.0.0.0:80 OSx Node.js
问题描述
我正在关注angularJS书中的教程并且必须设置服务器。这是server.js文件:
I'm following a tutorial in a angularJS book and have to setup a server. This is the server.js file:
var express = require('express');
var app = express();
app.use('/', express.static('./'));
app.listen(80);
我收到此错误:
$ node server.js
events.js:154
throw er; // Unhandled 'error' event
^
Error: listen EACCES 0.0.0.0:80
我已经知道,错误EACCES意味着我没有端口80的访问权限,但我不知道如何解决这个问题。
任何帮助非常感谢!
I know already, that the Error EACCES means that i don't have access rights to the port 80, but i don't know how to fix this. Any help much appreciated!
推荐答案
如果你需要在端口80上运行服务器,你应该使用反向代理,如 nginx 将使用特权端口上的系统帐户运行,并将请求代理到在非特权端口(> 1024)上运行的Node.js服务器。
If you need to run the server on port 80 you should use a reverse proxy like nginx that will run using a system account on a privileged port and proxy the requests to your Node.js server running on an unprivileged port (> 1024).
在开发环境中运行时,您可以自由地以root身份运行(即。 sudo node server.js
),但这在生产环境中相当危险。
When running in development environment you're pretty much free to run as root (ie. sudo node server.js
), but that is rather dangerous in production environment.
这是一个示例nginx配置,它将查看请求是否适用于文件系统中存在的文件,以及不,将请求代理到在端口9000上运行的Node.js服务器
Here's a sample nginx config that will see if the request is for a file that exists in the filesystem, and if not, proxy the request to your Node.js server running on port 9000
upstream yournodeapp {
server localhost:9000 fail_timeout=0;
keepalive 60;
}
server {
server_name localhost;
listen 80 default_server;
# Serve static assets from this folder
root /home/user/project/public;
location / {
try_files $uri @yournodeapp;
}
location @yournodeapp {
proxy_pass http://yournodeapp;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
这篇关于错误:侦听EACCES 0.0.0.0:80 OSx Node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!