Nginx installation,

Source: Internet
Author: User
Tags openssl library

Nginx installation,
1Nginx installation environment

Nginx is developed in C language. It is recommended to run it on linux. In this tutorial, Centos6.5 is used as the installation environment.

NGcc

To install nginx, you must first compile the source code downloaded from the official website. The compilation depends on the gcc environment. If there is no gcc environment.

Yum install gcc-c ++

NPCRE

PCRE (Perl Compatible Regular Expressions) is a Perl library, including a perl-Compatible Regular Expression Library. The http module of nginx uses pcre to parse regular expressions. Therefore, you need to install the pcre Library on linux.

Yum install-y pcre-devel

Note: pcre-devel is a secondary development library developed using pcre. Nginx also needs this library.

NZlib

The zlib library provides many compression and decompression methods. nginx uses zlib to perform gzip on the http package content. Therefore, you need to install the zlib library on linux.

Yum install-y zlib-devel

 

N openssl

OpenSSL is a powerful secure socket-layer cryptographic library that includes major cryptographic algorithms, common keys, certificate encapsulation management functions, and SSL protocols, and provides a wide range of applications for testing or other purposes.

Nginx not only supports http protocol, but also https (Transmission of http over ssl protocol). Therefore, you need to install the openssl library in linux.

Yum install-y openssl-devel

 

2 Compilation and installation (compressed file installation)

 

1. Extract

Tar-zxvf nginx-1.8.0.tar.gz

Cd nginx-1.8.0

 

2. configure

./Configure -- help to query detailed parameters (refer to the appendix of this tutorial: nginx compilation parameters)

The parameter settings are as follows:

./Configure \

-- Prefix =/usr/local/nginx \

-- Pid-path =/var/run/nginx. pid \

-- Lock-path =/var/lock/nginx. lock \

-- Error-log-path =/var/log/nginx/error. log \

-- Http-log-path =/var/log/nginx/access. log \

With-http_gzip_static_module \

-- Http-client-body-temp-path =/var/temp/nginx/client \

-- Http-proxy-temp-path =/var/temp/nginx/proxy \

-- Http-fastcgi-temp-path =/var/temp/nginx/fastcgi \

-- Http-uwsgi-temp-path =/var/temp/nginx/uwsgi \

-- Http-scgi-temp-path =/var/temp/nginx/scgi

 

Note: Specify the temporary file directory as/var/temp/nginx. Create the temp and nginx directories under/var.

 

 

3. Compile and install

Make

Make install

 

3 Start nginx

Cd/usr/local/nginx/sbin/

./Nginx

 

15098 is the id of the nginx master process, and 15099 is the id of the nginx Worker Process

 

Note: Run./nginx to start nginx. Here you can use-c to specify the loaded nginx configuration file, as shown below:

./Nginx-c/usr/local/nginx/conf/nginx. conf

If-c is not specified, nginx loads conf/nginx by default at startup. conf file. The address of this file can also be specified during nginx compilation and installation. /configure parameter (-- conf-path = pointing to the configuration file (nginx. conf ))

 

4 Stop nginx

Method 1: Stop quickly:

Cd/usr/local/nginx/sbin

./Nginx-s stop

This method is equivalent to first identifying the nginx process id and then using the kill command to forcibly kill the process.

 

Method 2: complete stop (recommended ):

Cd/usr/local/nginx/sbin

./Nginx-s quit

The stop process is to stop the nginx process after processing the task.

 

 

5 Restart nginx

Method 1: stop and start again (recommended ):

Restarting nginx is equivalent to stopping nginx and then starting nginx, that is, executing the Stop command before executing the start command.

As follows:

./Nginx-s quit

./Nginx

 

Method 2: Reload the configuration file:

After the nginx configuration file nginx. conf is modified, You need to restart nginx to make the configuration take effect. Use-s reload to stop nginx and then start nginx to apply the configuration information to nginx, as shown below:

./Nginx-s reload

 

6 Test

After nginx is installed successfully, start nginx to access nginx on the VM:

 

 

7 Start nginx at startup7.1 Write Shell script

Here we use the method of writing shell scripts for processing.

 

Vi/etc/init. d/nginx (enter the following code)

#! /Bin/bash

# Nginx Startup script for the Nginx HTTP Server

# It is v.0.0.2 version.

# Chkconfig:-85 15

# Description: Nginx is a high-performance web and proxy server.

# It has a lot of features, but it's not for everyone.

# Processname: nginx

# Pidfile:/var/run/nginx. pid

# Config:/usr/local/nginx/conf/nginx. conf

Nginxd =/usr/local/nginx/sbin/nginx

Nginx_config =/usr/local/nginx/conf/nginx. conf

Nginx_pid =/var/run/nginx. pid

RETVAL = 0

Prog = "nginx"

# Source function library.

./Etc/rc. d/init. d/functions

# Source networking configuration.

./Etc/sysconfig/network

# Check that networking is up.

[$ {NETWORKING} = "no"] & exit 0

[-X $ nginxd] | exit 0

# Start nginx daemons functions.

Start (){

If [-e $ nginx_pid]; then

Echo "nginx already running ...."

Exit 1

Fi

Echo-n $ "Starting $ prog :"

Daemon $ nginxd-c $ {nginx_config}

RETVAL =$?

Echo

[$ RETVAL = 0] & touch/var/lock/subsys/nginx

Return $ RETVAL

}

# Stop nginx daemons functions.

Stop (){

Echo-n $ "Stopping $ prog :"

Killproc $ nginxd

RETVAL =$?

Echo

[$ RETVAL = 0] & rm-f/var/lock/subsys/nginx/var/run/nginx. pid

}

# Reload nginx service functions.

Reload (){

Echo-n $ "Reloading $ prog :"

# Kill-HUP 'cat $ {nginx_pid }'

Killproc $ nginxd-HUP

RETVAL =$?

Echo

}

# See how we were called.

Case "$1" in

Start)

Start

;;

Stop)

Stop

;;

Reload)

Reload

;;

Restart)

Stop

Start

;;

Status)

Status $ prog

RETVAL =$?

;;

*)

Echo $ "Usage: $ prog {start | stop | restart | reload | status | help }"

Exit 1

Esac

Exit $ RETVAL

 

 

 

: Wq save and exit

 

7.2 Set File Access Permissions

 

Chmod a + x/etc/init. d/nginx (a + x ==> all user can execute all users can execute)

 

 

In this way, you can easily operate nginx on the console: view the current Nginx status, start Nginx, stop Nginx, and restart Nginx

 

 

If the nginx configuration file nginx is modified. conf. You can also use the preceding command to reload the new configuration file and run it. You can add this command to rc. in the local file, nginx is started by default when it is started.

 

7.3 Add the rc. local file

Vi/etc/rc. local

 

Add/etc/init. d/nginx start to save and exit. The next restart will take effect.

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.