Installation of Nginx under Linux

Source: Internet
Author: User
Tags openssl

1 nginx installation Environment

Nginx is a C language development, it is recommended to run on Linux , this tutorial uses Centos6.5 as the installation environment.

    • Gcc

installation nginx need to download the source code to compile, compile dependent gcc Environment, if there is no gcc Environment, need to install gcc :

Yum Install gcc-c++

    • PCRE

PCRE (perl Compatible Regular Expressions) is a perl Library that includes a perl - compatible regular expression library. the nginx http module uses pcre to parse the regular expression, so it needs to be in the Linux installed on Pcre Library.

Yum install-y pcre Pcre-devel

Note:pcre-devel is A two-time development library developed using PCRE. nginx also needs this library.

    • Zlib

Zlib Library provides a number of compression and decompression methods,nginx use zlib to the contents of the HTTP Packet gzip, so you need to install the zlib library on linux .

Yum install-y zlib Zlib-devel

    • Openssl

OpenSSL is a strong Secure Sockets Layer cipher library that includes key cryptographic algorithms, common key and certificate encapsulation management functions , and SSL protocols, and provides a rich set of applications for testing or other purposes.

Nginx not only supports HTTP protocol, but also supports HTTPS(that is , it transmits on SSL protocol. HTTP), so you need to install the OpenSSL library on Linux.

Yum Install-y OpenSSL Openssl-devel

2 Compiling the installation

Copy the nginx-1.8.0.tar.gz to a linux server.

Extract:

TAR-ZXVF nginx-1.8.0.tar.gz

CD nginx-1.8.0

1, configure

./configure--help Query Detail Parameters

The parameters are set as follows:

./configure \

--prefix=/usr/local/nginx \

--pid-path=/var/run/nginx/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: The temp file directory above is specified as /var/temp/nginx, and you need to Create Catalogue

2. Compile and install

Make

Make install

install successfully view installation directory :

3 start nginx

cd/usr/local/nginx/sbin/

./nginx

Query nginx process:

15098 is The process ID of the Nginx master process , and15099 is the nginx Process ID of the worker process

Note: Execute ./nginx start nginx, here you can Specify the loaded Nginx-C configuration file, as follows:

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

If you do not specify -C,nginx load the conf/nginx.conf file by default at startup , the address of this file can also be installed in the compilation Nginx when you specify ./configure The parameters ( --conf-path= point to configuration file ( nginx.conf ))

4 Stop nginx

mode 1, Quick stop:

Cd/usr/local/nginx/sbin

./nginx-s Stop

This method is equivalent to identifying the nginx process ID and then using the kill command to force the kill process.

mode 2, complete stop ( recommended):

Cd/usr/local/nginx/sbin

./nginx-s quit

This stop step is to wait until the Nginx process finishes processing the task to stop.

5 re-start nginx

mode 1, stop and restart ( recommended):

The restart of Nginx is equivalent to stop nginx and start nginx, that is, to execute the Stop command before executing the start command.

As follows:

./nginx-s quit

./nginx

mode 2, reload the configuration file:

when the nginx configuration file nginx.conf Modified, for the configuration to take effect need to restart nginx, use- s Reload The configuration information will be effective in nginx without having to stop nginx and start nginx , as follows:

./nginx-s Reload

6 Test

Nginx installation, start nginx, you can access the virtual machine nginx:

This indicates that the installation of Nginx was successful.

7 Boot from nginx7.1 Write Shell Script

here 's how to write a shell script to handle

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:--15# Description:ngin X is a high-performance web and proxy server.# it had a lot of features, but it's not for everyone.# PROCESSN ame:nginx# pidfile:/var/run/nginx.pid# config:/usr/local/nginx/conf/nginx.confnginxd=/usr/local/nginx/sbin/ Nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/var/run/nginx.pidretval=0prog= "Nginx" # Source function library. /etc/rc.d/init.d/functions# Source Networking configuration: /etc/sysconfig/network# Check that networking are up. [${networking} = "No"] && exit 0[-x $nginxd] | | Exit 0# Start Nginx daemons Functions.start () {If [-e $nginx _pid];then echo "Nginx already running ..." Exit 1fi E   Cho-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.re    Load () {echo-n $ "reloading $prog:" #kill-hup ' cat ${nginx_pid} ' Killproc $nginxd-hup retval=$? echo}# See how we were Called.case "$" instart) start; stop) stop;; reload) reload;; restart) stop start;;        Status) status $prog retval=$? ;; *) echo $ "Usage: $prog {start|stop|restart|reload|status|help}" exit 1esacexit $RETVAL

: Wq Save and exit

7.2 set access permissions for a file

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

This makes it easy to operate the Nginx in the console : View nginx current status, start nginx, stop nginx , restart Nginx ...

If you modify the nginx configuration file nginx.conf, you can also use the command above to reload the new configuration file and run it, you can add this command to rc.local file, the nginx will start by default when the boot

7.3 Add to rc.local file

Vi/etc/rc.local

Add a row /etc/init.d/nginx start to save and exit, and the next reboot will take effect.

Installation of Nginx under Linux

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.