使用node.js设置nginx
我已经将nginx设置为node.js应用程序的前端 我的nginx配置是:使用node.js设置nginx,node.js,nginx,Node.js,Nginx,我已经将nginx设置为node.js应用程序的前端 我的nginx配置是: worker_processes 1; error_log /tmp/logs/error.log; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; access_log /tmp/logs/access.log; sen
worker_processes 1;
error_log /tmp/logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /tmp/logs/access.log;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/sites-enabled/*;
# BELOW IS THE PART TO PROXY MY NODE.JS APP
upstream node_entry {
server unix:/tmp/express.sock
fail_timeout=0;
}
server {
listen 8888;
client_max_body_size 4G;
server_name localhost;
keepalive_timeout 5;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://node_entry;
}
}
}
我的node.js应用程序是:
express = require('express');
app = express.createServer();
app.get('/test', function(req, res){
res.send('TEST');
});
app.listen('/tmp/express.sock');
当我发出通知时:
curl-XGET'http://localhost:8888/test"
我得到一个错误,而不是代理到node.js应用程序
有什么想法吗 我也在做类似的事情,但都在一台主机上,而且我使用的是nginx和node都知道的预定义端口号(不过如果您能让它正常工作,我宁愿使用您的方式)
如果您让节点侦听特定端口,并将代理传递到
http://127.0.0.1:{那个端口}
?(假设两者都在同一台服务器上…我正在做一些类似的事情,但都在一台主机上,并且我使用的是nginx和node都知道的预定义端口号(尽管如果可以让它工作,我宁愿使用您的方式)
如果您让节点侦听特定端口,并将代理传递到
http://127.0.0.1:{那个端口}
?(假设两者都在同一台服务器上……您也可以根据本文检查套接字权限:var http=require(“http”);var oldUmask=process.umask(0000);var server=http.createServer(函数(请求、响应){/…});listen(“/some/socket/path”,function(){process.umask(oldUmask);})
我会检查这个,但是当我使用/tmp时,我觉得我应该不会有任何权限问题。谢谢,在我执行之后:chmod o+w/tmp/xxx.sock
,它可以工作!您也可以根据本文检查套接字权限:var http=require(“http”);var oldUmask=process.umask(0000);var server=http.createServer(函数(请求、响应){/…});listen(“/some/socket/path”,function(){process.umask(oldUmask);})
我会检查这个,但是当我使用/tmp时,我觉得我应该不会有任何权限问题。谢谢,在我执行之后:chmod o+w/tmp/xxx.sock
,它可以工作!