Nginx supports the node. JS Service Using reverse Proxy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.