Install NGINX+NODEJS+EXPRESS+MONGODB Environment on CentOS. __js

Source: Internet
Author: User
Tags bz2 curl mongodb openssl git clone

Using Nginx to reverse generation of Nodejs, each app can become more independent.

I. Installation of Nginx

Http://nginx.org/en/linux_packages.html#stable

On this page, select the corresponding system version

This is centos5.

Download installation package

wget http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm

Install RPM-IVH nginx-release-centos-5-0.el5.ngx.noarch.rpm

Formal Installation

Yum Install Nginx

Nginx Common Directory

1 configuration directory:/etc/nginx/
2 pid directory:/var/run/nginx.pid
3 Error log:/var/log/nginx/error.log
4 Access log:/var/log/nginx/access.log
5 Default Site Directory:/usr/share/nginx/html

Nginx Common Commands

1 Start Nginx:nginx
2 Restart Nginx:killall-hup Nginx
3 Test nginx configuration: nginx-t

Second, prepare

Advance preparation

Yum Install gcc-c++ openssl-devel Curl Git-core build-essential Libssl-dev

Make sure that Python

Python-v

If it's too low, upgrade.

wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2

Tar jxvf python-2.7.5.tar.bz2

CD Python2.6.7

./configure

Make && make install

Change the Python version in the system to point to
Mv/usr/bin/python/usr/bin/python.bak
Ln-s//usr/local/bin/python2.7/usr/bin/python
Resolving system Python Soft links point to python2.7 version, yum not working properly
Vi/usr/bin/yum
Change the text edit display #/usr/bin/python to #/usr/bin/python2.4 (your old version of Python) and save it.

Iii. installation of Nodejs

#wget http://nodejs.org/dist/v0.10.8/node-v0.10.8.tar.gz
# tar ZXVF node-v0.10.8.tar.gz
# CD node-v0.10.8
#./configure–prefix=/usr/local/nodejs–openssl-libpath=/usr/local/ssl/lib/–openssl-includes=/usr/local/ssl/ include/
#make
#make Install

modifying environment variables

#vi/etc/profile

Export Node_home=/usr/local/node/0.10.8/bin
Export path= $NODE _home: $PATH

These two paragraphs are added to the following section.

Export PATH USER LOGNAME MAIL HOSTNAME histsize inputrc

Four, install NPM EXPRESS JADE MONGODB FOREVER

Curl Https://npmjs.org/install.sh | Sh

NPM Install Express-g

NPM Install Jade-g

NPM Install Mongdb-g

NPM Install Forever-g

Five, configuration

Create Express Project

Express/www/test

Cd/www/test

NPM Install

Set the Ngnix to reverse generation

Cd/etc/nginx/conf.d

CP default.conf xxx.com.conf

Xxx.com.con is your domain name. corresponding configuration file

VI xxx.com.conf

The following code

server {
Listen 80;
server_name localhost;

#charset Koi8-r;
#access_log/var/log/nginx/log/host.access.log Main;

Location/{
root/usr/share/nginx/html;
Index index.html index.htm;
}

To

server {
Listen 80;
server_name xxx.com www.xxx.com;

#charset Koi8-r;
#access_log/var/log/nginx/log/host.access.log Main;

Location/{

Proxy_pass              http://127.0.0.1:3000/;
Proxy_redirect off          ;
Proxy_set_header        x-real-ip       $remote _addr;
Proxy_set_header        x-forwarded-for $proxy _add_x_forwarded_for;

}

Save and

#source/etc/profile

With Ngnix agent internal application, so you can build a number of NODEJS applications, listening to different ports, phased management

Restart Nginx

#killall-hup Nginx

Configure Forever to allow forever to execute permanently

Download Edit a configuration file

#git Clone Https://github.com/chovy/node-startup.git
#vi Node-app
The top lines are set as follows

#/bin/sh
Node_exec=/usr/local/node/0.10.8/bin/node
node_env= "Testpro"
node_app= ' App.js '
App_dir= '/www/test ';
pid_file= $APP _dir/pid/app.pid
log_file= $APP _dir/log/app.log
config_dir= $APP _dir/config

Save after modification

Then move to/ETC/INIT.D.

#cp NODE-APP/ETC/INT.D

Renaming

#mv/etc/init.d/node-app/etc/init.d/napp-xxxcom

#chmod 755/etc/init.d/napp-xxxcom

#chkconfig/etc/init.d/napp-xxxcom on

That's it, okay?

Start the service manually napp-xxxcom start

Even restarting the system will be activated properly

Related Article

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.