Nginx compilation and Installation

Source: Internet
Author: User

Nginx compilation and Installation

Nginx is a high-performance Web and reverse proxy server with many excellent features:

As a Web server: Compared with Apache, Nginx uses less resources and supports more concurrent connections, reflecting higher efficiency. This makes Nginx particularly popular among virtual host providers. It supports responses with up to 50,000 concurrent connections. Thanks to Nginx for choosing epoll and kqueue as the development model.

As a Server Load balancer: Nginx can support both Rails and PHP internally, or serve as an HTTP proxy server. Nginx is written in C. Both system resource overhead and CPU usage are much more efficient than Perlbal.

As a mail proxy server: Nginx is also a very good mail proxy server (one of the earliest development purposes of this product is also as a mail proxy server), Last. fm describes the success and wonderful use experience.

Nginx installation is very simple and configuration files are very simple (perl syntax is also supported). servers with few buckets: Nginx is easy to start and can run almost without interruption, it does not need to be restarted even if it is running for several months. You can also upgrade the software without interruption.
 
Compiling environment:
[Root @ www ~] # Yum groupinstall Development Tools
[Root @ www ~] # Yum install pcre-devel openssl-devel

Obtain the nginx program source code package:

[Root @ www ~] # Ll
Total 888
Drwxr-xr-x 9 1001 1001 4096 Dec 27 nginx-1.6.2
-Rw-r -- 1 root 804164 Sep 16 nginx-1.6.2.tar.gz
-Rw-r -- 1 root 29542 Apr 23 2014 nginx. vim

Decompress the source package:

[Root @ www ~] # Tar xf nginx-1.6.2.tar.gz
[Root @ www ~] # Cd nginx-1.6.2

Create an nginx administrator:

[Root @ www nginx-1.6.2] # useradd-M-s/sbin/nologin nginx
[Root @ www.nginx-1.6.2] # id nginx
Uid = 500 (nginx) gid = 500 (nginx) groups = 500 (nginx)

Install nginx through source code compilation:

During compilation and installation, we need to define the directories required for various configurations, so we need to create some directories:

Log storage directory:

[Root @ www ~] # Mkdir/var/log/nginx

Various cache directories, clients, proxies, and fastcgi directories:

[Root @ www ~] # Mkdir-pv/var/tmp/nginx/{client, proxy, fastcgi}
Mkdir: created directory '/var/tmp/nginx'
Mkdir: created directory '/var/tmp/nginx/client'
Mkdir: created directory '/var/tmp/nginx/proxy'
Mkdir: created directory '/var/tmp/nginx/fastcgi'
[Root @ www ~] #

Run the following command to view the Help file:

[Root @ www nginx-1.6.2] #./configure -- help | less

Start compiling nginx:

[Root @ www nginx-1.6.2] #. /configure -- prefix =/usr/local/nginx -- conf-path =/etc/nginx. conf -- user = nginx -- group = nginx -- error-log-path =/var/log/nginx/error. log -- http-log-path =/var/log/nginx/access. log -- pid-path =/var/run/nginx. pid -- lock-path =/var/lock/nginx. lock -- with-http_ssl_module -- with-http_stub_status_module -- with-http_gzip_static_module -- with-http_flv_module -- with-http_mp4_module -- http-client-body-temp-path =/var/tmp/nginx/client -- http-proxy-temp-path =/ var/tmp/nginx/proxy -- http-fastcgi-temp-path =/var/tmp/nginx/fastcgi

Install nginx:

[Root @ www nginx-1.6.2] # make & make install

Check installation:

View the installation directory

[Root @ www ~] # Ls/usr/local/nginx/
Html sbin
[Root @ www ~] # Ls/usr/local/nginx/sbin/
Nginx

View the configuration file directory:

[Root @ www ~] # Ls/etc/nginx/
Fastcgi. conf fastcgi_params.default mime. types nginx. conf. default uwsgi_params
Fastcgi. conf. default koi-utf mime. types. default scgi_params uwsgi_params.default
Fastcgi_params koi-win nginx. conf scgi_params.default win-utf

Environment variable settings:

[Root @ www ~] # Echo "export PATH =/usr/local/nginx/sbin: $ PATH">/etc/profile. d/nginx. sh
[Root @ www ~] # Source/etc/profile. d/nginx. sh

View the nginx version:

[Root @ www ~] # Nginx-v
Nginx version: nginx/1.6.2

Test the nginx configuration file:

[Root @ www ~] # Nginx-t
Nginx: the configuration file/etc/nginx. conf syntax is OK
Nginx: configuration file/etc/nginx. conf test is successful

Provide nginx service script:

[Root @ www ~] # Vim/etc/rc. d/init. d/nginx
#! /Bin/bash
#
# Nginx-this script starts and stops the nginx daemon
#
# Chkconfig:-85 15
# Description: Nginx is an HTTP (S) server, HTTP (S) reverse \
# Proxy and IMAP/POP3 proxy server
# Processname: nginx
# Config:/etc/nginx. conf
# Config:/etc/sysconfig/nginx
# Pidfile:/var/run/nginx. pid

# Source function library.
./Etc/rc. d/init. d/functions

# Source networking configuration.
./Etc/sysconfig/network

# Check that networking is up.
["$ NETWORKING" = "no"] & exit 0

Nginx = "/usr/local/nginx/sbin/nginx"
Prog = $ (basename $ nginx)

NGINX_CONF_FILE = "/etc/nginx. conf"

[-F/etc/sysconfig/nginx] &./etc/sysconfig/nginx

Lockfile =/var/lock/subsys/nginx

Make_dirs (){
# Make required directories
User = 'nginx-V 2> & 1 | grep "configure arguments:" | sed's/[^ *] * -- user = \ ([^] * \). */\ 1/G '-'
Options = '$ nginx-V 2> & 1 | grep' configure arguments :''
For opt in $ options; do
If ['echo $ opt | grep'. *-temp-path'']; then
Value = 'echo $ opt | cut-d "="-f 2'
If [! -D "$ value"]; then
# Echo "creating" $ value
Mkdir-p $ value & chown-R $ user $ value
Fi
Fi
Done
}

Start (){
[-X $ nginx] | exit 5
[-F $ NGINX_CONF_FILE] | exit 6
Make_dirs
Echo-n $ "Starting $ prog :"
Daemon $ nginx-c $ NGINX_CONF_FILE
Retval =$?
Echo
[$ Retval-eq 0] & touch $ lockfile
Return $ retval
}

Stop (){
Echo-n $ "Stopping $ prog :"
Killproc $ prog-QUIT
Retval =$?
Echo
[$ Retval-eq 0] & rm-f $ lockfile
Return $ retval
}

Restart (){
Configtest | return $?
Stop
Sleep 1
Start
}

Reload (){
Configtest | return $?
Echo-n $ "Reloading $ prog :"
Killproc $ nginx-HUP
RETVAL =$?
Echo
}

Force_reload (){
Restart
}

Configtest (){
$ Nginx-t-c $ NGINX_CONF_FILE
}

Rh_status (){
Status $ prog
}

Rh_status_q (){
Rh_status>/dev/null 2> & 1
}

Case "$1" in
Start)
Rh_status_q & exit 0
$1
;;
Stop)
Rh_status_q | exit 0
$1
;;
Restart | configtest)
$1
;;
Reload)
Rh_status_q | exit 7
$1
;;
Force-reload)
Force_reload
;;
Status)
Rh_status
;;
Condrestart | try-restart)
Rh_status_q | exit 0
;;
*)
Echo $ "Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest }"
Exit 2
Esac

Add the service script to the system startup and set automatic start upon startup:

[Root @ www ~] # Chkconfig -- list nginx
Service nginx supports chkconfig, but is not referenced in any runlevel (run 'chkconfig -- add nginx ')
[Root @ www ~] # Chkconfig -- add nginx
[Root @ www ~] # Chkconfig nginx on
 

Set the service script to enable the execution permission:

[Root @ www ~] # Chmod + x/etc/rc. d/init. d/nginx

Start the nginx Server:
[Root @ www ~] # Vim/etc/rc. d/init. d/nginx
[Root @ www ~] # Service nginx start
Starting nginx: [OK]
[Root @ www ~] # Ss-tunl | grep 80
Tcp LISTEN 0 128 ::: 38804 :::*
Tcp LISTEN 0 128 *: 80 *:*

The basic introduction to nginx is complete!

-------------------------------------- Split line --------------------------------------

Deployment of Nginx + MySQL + PHP in CentOS 6.2

Build a WEB server using Nginx

Build a Web server based on Linux6.3 + Nginx1.2 + PHP5 + MySQL5.5

Performance Tuning for Nginx in CentOS 6.3

Configure Nginx to load the ngx_pagespeed module in CentOS 6.3

Install and configure Nginx + Pcre + php-fpm in CentOS 6.4

Nginx installation and configuration instructions

Nginx log filtering using ngx_log_if does not record specific logs

-------------------------------------- Split line --------------------------------------

Nginx details: click here
Nginx: click here

This article permanently updates the link address:

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.