Wụnye ma chịkọta Nginx 1.10.0 (Stable Release) site na isi mmalite na RHEL/CentOS 7.0


Nginx bụ Webserver na-eto ngwa ngwa taa na ịntanetị ọha na-eche ihu sava n'ihi ụdị modular mepere emepe n'efu, arụmọrụ dị elu, nkwụsi ike, faịlụ nhazi dị mfe, ihe owuwu asynchronous (mmemme na-akpata) yana akụrụngwa dị ala achọrọ. ịgba ọsọ.

  1. Nwụnye RHEL 7.0
  2. kacha nta
  3. Ndebanye aha RedHat na ebe nchekwa na RHEL 7.0

  1. Nwụnye nke kacha nta nke CentOS 7.0

  1. Tụzie adreesị IP static na RHEL/CentOS 7.0

Nkuzi a ga-eduzi gị na ịwụnye ụdị kwụsiri ike nke Nginx 1.10.0 na Red Hat Enterprise ma ọ bụ CentOS 7 sitere na isi mmalite, n'ihi na enyo nchekwa RHEL/CentOS 7 anaghị enye ngwugwu ọnụọgụ abụọ. Ọ bụrụ n’ịchọrọ ịzenarị nrụnye isi mmalite, ị nwere ike itinye ebe nchekwa Nginx gọọmentị wee wụnye ngwugwu ọnụọgụ abụọ (ụdị dị bụ 1.9.x) site n'enyemaka nke Onye njikwa ngwugwu Yum dị ka egosiri:

Iji mee ka nginx ukara yum repository maka RHEL/CentOS 7, mepụta faịlụ /etc/yum.repos.d/nginx.repo na ọdịnaya ndị a:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1

Dochie \centos na rhel, dabere na nkesa ị na-eji wee tinye nginx na yum ngwugwu dị ka egosiri:

# yum install nginx

Ihe dị mkpa: Biko mara, na-esote nginx yum repositories gọọmentị ga-enye gị ụdị nginx ochie, ọ bụrụ n'ezie na ịchọrọ ịmepụta ụdị Nginx kacha ọhụrụ, m na-atụ aro ka ịgbaso ntinye isi mmalite dị ka egosiri n'okpuru.

Iji nchịkọta isi mmalite na nrụnye nwere ụfọdụ uru, n'ihi na ị nwere ike ịwụnye ụdị kachasị ọhụrụ dị, ị nwere ike tweak nhazi Nginx site na ịgbakwunye ma ọ bụ wepụ modul, gbanwee usoro nrụnye, ma ọ bụ ntọala ndị ọzọ dị mkpa, na okwu ndị ọzọ, ị nwere a njikwa zuru oke n'elu usoro nhazi.

Kwụpụ 1: Budata, chịkọta ma wụnye Nginx

1. Tupu ịmalite nchịkọta Nginx na nhazi nhazi, jide n'aka na ị nwere C/C ++ compiler, PCRE ( Perl Compatible Regular Expressions ), Zlib Compression Library na OpenSSL (ma ọ bụrụ na ị bu n'obi na-agba ọsọ Nxing na nkwado SSL) ngwugwu arụnyere na igwe gị site n'inye iwu na-esonụ.

# yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.mirror.net.in
 * extras: centos.mirror.net.in
 * updates: centos.mirror.net.in
Package 1:make-3.82-21.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-4.el7 will be installed
--> Processing Dependency: libgomp = 4.8.5-4.el7 for package: gcc-4.8.5-4.el7.x86_64
--> Processing Dependency: cpp = 4.8.5-4.el7 for package: gcc-4.8.5-4.el7.x86_64
--> Processing Dependency: libgcc >= 4.8.5-4.el7 for package: gcc-4.8.5-4.el7.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-4.el7.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-4.8.5-4.el7.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.5-4.el7.x86_64
---> Package gcc-c++.x86_64 0:4.8.5-4.el7 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-4.el7 for package: gcc-c++-4.8.5-4.el7.x86_64
--> Processing Dependency: libstdc++ = 4.8.5-4.el7 for package: gcc-c++-4.8.5-4.el7.x86_64
---> Package openssl-devel.x86_64 1:1.0.1e-51.el7_2.4 will be installed
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-51.el7_2.4 for package: 1:openssl-devel-1.0.1e-51.el7_2.4.x86_64
--> Processing Dependency: krb5-devel(x86-64) for package: 1:openssl-devel-1.0.1e-51.el7_2.4.x86_64
---> Package pcre-devel.x86_64 0:8.32-15.el7 will be installed
--> Processing Dependency: pcre(x86-64) = 8.32-15.el7 for package: pcre-devel-8.32-15.el7.x86_64
---> Package zlib-devel.x86_64 0:1.2.7-15.el7 will be installed
--> Processing Dependency: zlib = 1.2.7-15.el7 for package: zlib-devel-1.2.7-15.el7.x86_64
...

2. Ugbu a gaa na ibe gọọmentị Nginx wee jide ụdị Stable kachasị ọhụrụ (nginx 1.10.0) dị na iji wgetiwu, wepụ TAR Archive wee tinye Nginx amịpụtara ndekọ, na-eji usoro iwu ndị a.

# wget http://nginx.org/download/nginx-1.10.0.tar.gz
# tar xfz nginx-1.10.0.tar.gz
# cd nginx-1.10.0/
# ls -all
--2016-03-21 09:30:15--  http://nginx.org/download/nginx-1.10.0.tar.gz
Resolving nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 908954 (888K) [application/octet-stream]
Saving to: ‘nginx-1.10.0.tar.gz’

100%[=====================================================================================================================================================>] 9,08,954    81.0KB/s   in 11s    

2016-03-21 09:30:27 (77.4 KB/s) - ‘nginx-1.10.0.tar.gz’ saved [908954/908954]

3. Nzọụkwụ ọzọ bụ ịhazi usoro ntinye Nginx. Jiri hazi faịlụ iji hụ anya nhọrọ nhazi na modul chọrọ maka usoro nchịkọta gị site na iji iwu na-esonụ wee hụ na ị nọ na nginx-1.6.0/ ụzọ.

# ./configure --help
-help                             print this message

  --prefix=PATH                      set installation prefix
  --sbin-path=PATH                   set nginx binary pathname
  --modules-path=PATH                set modules path
  --conf-path=PATH                   set nginx.conf pathname
  --error-log-path=PATH              set error log pathname
  --pid-path=PATH                    set nginx.pid pathname
  --lock-path=PATH                   set nginx.lock pathname

  --user=USER                        set non-privileged user for
                                     worker processes
  --group=GROUP                      set non-privileged group for
                                     worker processes

  --build=NAME                       set build name
  --builddir=DIR                     set build directory

  --with-select_module               enable select module
  --without-select_module            disable select module
  --with-poll_module                 enable poll module
  --without-poll_module              disable poll module

  --with-threads                     enable thread pool support

  --with-file-aio                    enable file AIO support
  --with-ipv6                        enable IPv6 support

  --with-http_ssl_module             enable ngx_http_ssl_module
  --with-http_v2_module              enable ngx_http_v2_module
...

4. Ugbu a, ọ bụ oge iji chịkọta Nginx na nhazi gị kpọmkwem na modul nyeere ma ọ bụ nwee nkwarụ. Maka nkuzi a, modul ndị a na nkọwapụta ebe ejiri ya, mana ị nwere ike ịmegharị mkpokọta ahụ n'ihe ọ bụla dabara gị mkpa.

  1. –user=nginx –group=nginx => Onye ọrụ na otu Nginx ga-agba ọsọ dị ka.
  2. –prefix=/etc/nginx => akwụkwọ ndekọ aha maka faịlụ sava (nginx.conf faịlụ na faịlụ nhazi ndị ọzọ) - ndabara bụ /usr/local/nginx directory.
  3. –sbin-path=/usr/sbin/nginx => Nginx nwere ike ime ebe faịlụ.
  4. –conf-path=/etc/nginx/nginx.conf => na-ahazi aha faịlụ nhazi nginx.conf – ị nwere ike ịgbanwe ya.
  5. –error-log-path=/var/log/nginx/error.log => na-ahazi ebe faịlụ ndekọ njehie Nginx.
  6. –http-log-path=/var/log/nginx/access.log => na-ahazi ebe faịlụ ntinye Nginx.
  7. –pid-path=/var/run/nginx.pid => na-ahazi aha faịlụ NJ isi.
  8. –lock-path=/var/run/nginx.lock => ewepụta aha maka faịlụ mkpọchi Nginx.
  9. –with-http_ssl_module => na-enyere aka iwulite HTTPS modul – ọ bụghị na ndabara wuru ma chọọ ọbá akwụkwọ OpenSSL.
  10. –with-pcre => na-edobe ụzọ isi nweta ọbaakwụkwọ PCRE – esiteghị na ndabara wuru ya wee chọọ ọba akwụkwọ PCRE.

Ka ilele ndepụta modulu Nginx niile gaa na ibe weebụ Nginx Wiki na http://wiki.nginx.org/Modules.

Ọ bụrụ na ịchọghị otu modul arụnyere na Nginx ị nwere ike gbanyụọ ya site na iji iwu a.

--without-module_name

Ugbu a malite ịchịkọta Nginx site n'inye iwu na-esonụ, nke ga-eji nhazi na modul niile a tụlere n'elu (jide n'aka na iwu ahụ dị n'otu ahịrị).

# ./configure --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --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/run/nginx.lock --with-http_ssl_module --with-pcre
checking for OS
 + Linux 3.10.0-229.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for O_PATH ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for sched_setaffinity() ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for poll() ... found
checking for /dev/poll ... not found
...

5. Mgbe usoro nchịkọta ahụ mechara nyochaa usoro niile achọrọ dị ka GNU C compiler, PCRE na OpenSSL Library, ọ na-emepụta faịlụ make.conf wee wepụta nchịkọta nke nhazi niile.

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library

  nginx path prefix: "/etc/nginx"
  nginx binary file: "/usr/sbin/nginx"
  nginx modules path: "/etc/nginx/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

6. Nzọụkwụ ikpeazụ bụ iji wuo ọnụọgụ abụọ site na iji meeiwu, nke nwere ike iwepụta oge iji rụchaa dabere na akụrụngwa akụrụngwa gị, wee wụnye Nginx na sistemụ gị na mee wụnye iwu.

Kpachara anya na mere install chọrọ ohere mgbọrọgwụ iji rụọ ọrụ nrụnye, yabụ ọ bụrụ na ịbanyeghị na akaụntụ mgbọrọgwụ jiri onye ọrụ nwere sudo.

# make
# make install
make -f objs/Makefile
make[1]: Entering directory `/root/nginx-1.10.0'
make[1]: Warning: File `src/core/nginx.h' has modification time 3110036 s in the future
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/nginx.o \
	src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_log.o \
	src/core/ngx_log.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_palloc.o \
	src/core/ngx_palloc.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_array.o \
	src/core/ngx_array.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_list.o \
	src/core/ngx_list.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_hash.o \
	src/core/ngx_hash.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_buf.o \
	src/core/ngx_buf.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_queue.o \
...
make -f objs/Makefile install
make[1]: Entering directory `/root/nginx-1.10.0'
make[1]: Warning: File `src/core/nginx.h' has modification time 3109935 s in the future
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/nginx.o \
	src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_log.o \
	src/core/ngx_log.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_palloc.o \
	src/core/ngx_palloc.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_array.o \
	src/core/ngx_array.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_list.o \
	src/core/ngx_list.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_hash.o \
	src/core/ngx_hash.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_buf.o \
	src/core/ngx_buf.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_queue.o \
...

Kwụpụ 2: Tweak Nginx wee mepụta edemede INIT

7. Mgbe usoro nrụnye gwụchara na ihe ịga nke ọma tinye nginx onye ọrụ sistemụ (na /etc/nginx/ dị ka akwụkwọ ndekọ ụlọ ya na enweghị shei dị mma), onye ọrụ na Nginx. ga-agba ọsọ dị ka site n'inye iwu na-esonụ.

# useradd -d /etc/nginx/ -s /sbin/nologin nginx

8. N'ihi na n'usoro nchịkọta, anyị akọwapụtala na Nginx ga-esi na nginx onye ọrụ sistemụ, mepee faịlụ nginx.conf wee gbanwee nkwupụta onye ọrụ ka ọ bụrụ nginx >.

# nano /etc/nginx/nginx.conf

Ebe a chọta ma gbanwee onye ọrụ yana, kwa, akwụkwọ nkwupụta ọnọdụ mgbọrọgwụ, yana nhọrọ ndị a.

user nginx;
location / {
                root /srv/www/html;
                autoindex on;
                index index.html index.htm;

9. Tupu ịmalite Nginx, jide n'aka na ị mepụtara ụzọ mgbọrọgwụ akwụkwọ weebụ, wee malite nginx site na iji iwu a.

# mkdir -p /srv/www/html
# /usr/sbin/nginx

Ọ bụrụ na ịchọrọ ịlele ma Nginx na-agba ọsọ site na iji shei gị ozugbo, gbaa netstat iwu iji nyochaa njikọ ege ntị.

# netstat -tulpn | grep nginx

10. Iji nyochaa ya site na sistemụ dịpụrụ adịpụ, gbakwunye iwu Firewall iji mepee njikọ na mpụga na Port 80, mepee ihe nchọgharị wee mee URL na adreesị IP nke ihe nkesa gị na http://server_IP.

# firewall-cmd --add-service=http  ## For on-fly rule
# firewall-cmd --permanent --add-service=http  ## For permanent rule
# systemctl restart firewalld

11. Iji jikwaa usoro Nginx jiri iwu ndị a.

  1. nginx -V = na-egosiputa modul na nhazi Nginx
  2. nginx -h = nhọrọ enyemaka
  3. nginx = malite usoro Nginx
  4. nginx -s stop = kwụsị usoro Nginx
  5. nginx -s bugharia = bugharia usoro Nginx

# nginx -V
nginx version: nginx/1.10.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --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/run/nginx.lock --with-http_ssl_module --with-pcre

12. Ọ bụrụ na ịchọrọ ijikwa Nginx daemon usoro site na init RHEL/CentOS script, mepụta nginx faịlụ na /etc/init.d/ usoro ụzọ, na, mgbe ahụ, ị nwere ike iji ọrụ ma ọ bụ systemctl iwu iji jikwaa usoro a.

# nano /etc/init.d/nginx

Tinye ọdịnaya faịlụ ndị a.

#!/bin/sh
#
# 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/nginx.conf
# pidfile:     /var/run/nginx.pid
# user:        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

nginx="/usr/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"
lockfile=/var/run/nginx.lock

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    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
    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

13. Mgbe emechara faịlụ Nginx init, tinye ikike ikike ma jikwaa daemon site na iji nhọrọ iwu dị n'okpuru.

# chmod +x /etc/init.d/nginx
# service nginx start|stop|restart|reload|force_reload|configtest|condrestart
# systemctl start|stop|restart nginx

14. Ọ bụrụ na ị chọrọ ka Nginx usoro-wide jiri iwu na-esonụ na-amalite n'oge buut.

# chkconfig nginx on

OR

# systemctl enable nginx

Ọ gwụla! Ugbu a ị nwere ụdị Nginx kachasị ọhụrụ arụnyere na RHEL/CentOS 7 gị. Na nkuzi na-esote m ga-atụle ka esi etinye ma mee ka PHP-FPM nhazi usoro nhazi Nginx FastCGI Gateway.

Gụọkwa: Ntuziaka kacha mma maka nchekwa, sie ike na melite arụmọrụ nke Nginx Web Server