Objective
node. js itself can be used as a Web server, but what if you want to open multiple node. JS applications on a single machine? One answer is to use Nginx as a reverse proxy. The role of the reverse proxy here is that when the proxy server receives the request, it forwards the request to the destination server and then gets the data back.
Steps
I. Normal use of node. js to open Web services
varHTTP = require ('http'); Http.createserver (function (request, response) {Response.writehead ( $, {'Content-type':'Text/plain'}); Response.End ('Hello world\n');}). Listen (1337); Console.log ('Server running at http://127.0.0.1:1337/');
Second, configure Nginx for the domain name
[[email protected] vhost]# ls default . conf node.ruanwenwu.cn.conf test.ruanwenwu.conf www.tjzsyl.com.conflaravel.ruanwenwu.cn.conf wss.ruanwenwu.cn.conf www.tjzsyl.com.conf.bak[[email protected] vhost]# pwd
Node.ruanwenwu.cn.conf:
server{ ; server_name node.ruanwenwu.cn; / { proxy_pass http://127.0.0.1:1337; }}
The steps are simple, and these are all right.
Finally, take a look at our results: http://node.ruanwenwu.cn
Nginx supports the node. JS Service Using reverse Proxy