1.nginx配置文件
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream fzjunh {
server 127.0.0.1:3000;
server 127.0.0.1:3001;
keepalive 3000;
}
server {
listen 80;
server_name localhost;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
#proxy_pass http://127.0.0.1:3000;
proxy_pass http://fzjunh;
proxy_redirect default;
#root html;
#index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
2.测试代码
//server.js
var http = require('http');
// 创建服务器
http.createServer( function (request, response) {
response.end('3000');
}).listen(3000);
// 控制台会输出以下信息
console.log('Server running at http://127.0.0.1:3000/');
//server1.js
var http = require('http');
// 创建服务器
http.createServer( function (request, response) {
response.end('3001');
}).listen(3001);
// 控制台会输出以下信息
console.log('Server running at http://127.0.0.1:3001/');