Install Nginx1.9.3 in Linux
Linux: CentOS6.5 64bit
Latest Nginx: 1.9.3
Nginx 1.9.3 release and download, high-performance Web Server
1. Download Nginx
[Root @ bkjia softs] # wget http://nginx.org/download/nginx-1.9.3.tar.gz
2. Install dependent Libraries
[Root @ bkjia softs] # yum-y install gcc automake autoconf libtool make libxml2-devel libxslt-devel perl-ExtUtils-Embed
[Root @ bkjia softs] # yum install gcc-c ++
3. Install pcre to rewrite
[Root @ bkjia softs] # wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
Install pcre on/usr/local/src
[Root @ bkjia softs] # cd/usr/local/src/
[Root @ bkjia src] # tar pcre-8.37.tar.gz
[Root @ bkjia src] # cd pcre-8.37
[Root @ bkjia pcre-8.37] #./configure
[Root @ bkjia pcre-8.37] # make
[Root @ bkjia pcre-8.37] # make install
4. Install zlib for gzip Compression
Install to/usr/local/src
[Root @ bkjia src] # wget http://zlib.net/zlib-1.2.8.tar.gz
[Root @ bkjia src] # tar-zxv zlib-1.2.8.tar.gz
[Root @ bkjia src] # cd zlib-1.2.8
[Root @ bkjia zlib-1.2.8] #./configure
[Root @ bkjia zlib-1.2.8] # make
[Root @ bkjia zlib-1.2.8] # make install
5. Install openssl for ssl
Install to/usr/local/src
[Root @ bkjia src] # wget http://www.openssl.org/source/openssl-1.0.2d.tar.gz
[Root @ bkjia src] # tar-zxvf openssl-1.0.2d.tar.gz
[Root @ bkjia src] # cd openssl-1.0.2d
6. Install Nginx
Install to/usr/local/nginx
[Root @ bkjia softs] # cd/usr/local
[Root @ bkjia local] # pwd
/Usr/local
[Root @ bkjia local] #
[Root @ bkjia local] # nginx-1.9.3 cd
[Root @ bkjia nginx-1.9.3] #./configure \
-- Prefix =/usr/local/nginx
With-http_ssl_module \
-- With-pcre =/usr/local/src/pcre-8.37 \
-- With-zlib =/usr/local/src/zlib-1.2.8 \
-- With-openssl =/usr/local/src/openssl-1.0.1d
[Root @ bkjia nginx-1.9.3] # make
[Root @ bkjia nginx-1.9.3] # make install
7. Set auto-start upon startup
Create an nginx file under/etc/init. d/
[Root @ bkjia init. d] # vi nginx
Write the following content:
#! /Bin/bash
# Nginx Startup script for the Nginx HTTP Server
# 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:/usr/local/nginx/logs/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 =/usr/local/nginx/logs/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
Grant executable permissions
[Root @ bkjia init. d] # chmod a + x/etc/init. d/nginx
Set startup
[Root @ bkjia init. d] # chkconfig -- add/etc/init. d/nginx
[Root @ bkjia init. d] # chkconfig nginx on
Start:
[Root @ bkjia lib64] # service nginx start
Starting nginx: [OK]
[Root @ bkjia lib64] #
8. Start error handling
[Root @ bkjia init. d] # service nginx start
Starting nginx:/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre. so.1: cannot open shared object file: No such file or directory
[FAILED]
Use ldd to view dynamic libraries contained in nginx
[Root @ bkjia src] # ldd $ (which/usr/local/nginx/sbin/nginx)
Linux-vdso.so.1 => (0x00007fff89fff000)
Libpthread. so.0 =>/lib64/libpthread. so.0 (0x0000003978400000)
Libcrypt. so.1 =>/lib64/libcrypt. so.1 (0x00000020.b800000)
Libpcre. so.1 => not found
Libcrypto. so.10 =>/usr/lib64/libcrypto. so.10 (0x00007ffd9a115000)
Libz. so.1 =>/lib64/libz. so.1 (0x0000000000c00000)
Libc. so.6 =>/lib64/libc. so.6 (0x0000003978000000)
/Lib64/ld-linux-x86-64.so.2 (0x0000003977800000)
Libfreebl3.so =>/lib64/libfreebl3.so (0x0000000000ac00000)
Libdl. so.2 =>/lib64/libdl. so.2 (0x0000003978800000)
[Root @ bkjia src] # cd/
You can see libpcre. so.1 => not found
Solution:
Enter the manual link in the/lib64 directory
[Root @ bkjia init. d] # cd/lib64/
[Root @ bkjia lib64] # ln-s libpcre. so.0.0.1 libpcre. so.1
Then start.
For more Nginx tutorials, see the following:
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
Nginx details: click here
Nginx: click here
This article permanently updates the link address: