Install and use nginx with node. js

Source: Internet
Author: User

Recently, I wanted to create a Web site for my team. I originally wanted to use Apache. Later I thought that nginx is now popular. Let's take a look at nginx.

 

Http://nginx.org/click download windows version, my version is 1.1.14, compressed package only 1.08 M, really small ah. I decompress it to D: \ Developer \ nginx-1.1.14. double-click nginx.exe and a black screen will disappear. View Processes

Start two processes

Enter http: // localhost/in the browser/

OK

However, it is too troublesome to enable or disable the process manually. It would be nice to have a tray like apache.

Google, really have, software called nginxtray official website http://nginxtray.codeplex.com/is codeplex open source projects, I under the 1.0 version

Decompress the package to D: \ Developer \ NginxTray 1.0.

Double-click NginxTray.exe to execute multiple icons on the tray.

Enable, disable, and restart functions. However, you must configure the nginx location before use.

Click settings

Nginx Directory is the decompressed Directory of nginx, my is D: \ Developer \ nginx-1.1.14,Note: Be careful when replacing it. Some of them are covered by Nginx Directory labels, so I spent half a day.

Now it is easy to start and close.

D: \ Developer \ nginx-1.1.14 \ conf \ nginx. conf is the main configuration file is a bit like httpd. conf, combined with node. js need to modify the file, add under server {

Location/node {
Proxy_pass http: // 127.0.0.1: 1337;
}

Node. js example. js file is as follows:




Var http = require ('http ');
Http. createServer (function (req, res ){
Res. writeHead (200, {'content-type': 'text/plain '});
Res. end ('Hello World \ n ');
}). Listen (1337, "127.0.0.1 ");
Console. log ('server running at http: // 127.0.0.1: 1337/'); execute node example. js on the command line.


 

Restart nginx

Enter http://www.bkjia.com/node in the address bar

 



OK is used in combination

From dellheng's column

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.