Fi sii ki o ṣajọ "Nginx 1.10.0" (Tu silẹ Iburo) lati Awọn orisun ni RHEL/CentOS 7.0
Nginx jẹ Webserver ti nyara kiakia julọ loni lori intanẹẹti ti gbogbo eniyan ti nkọju si awọn apẹẹrẹ modulu orisun ṣiṣi ọfẹ, iṣẹ giga, iduroṣinṣin, awọn faili atunto ti o rọrun, faaji asynchronous (iwakọ iṣẹlẹ) ati awọn orisun kekere ti o nilo lati ṣiṣe.
- Fifi sori Pọọku ti RHEL 7.0
- Ṣiṣe alabapin RedHat ti nṣiṣe lọwọ ati Awọn ibi ipamọ lori RHEL 7.0
- Fifi sori Kere ti CentOS 7.0
- Ṣeto Adirẹsi IP Aimi lori RHEL/CentOS 7.0
Ikẹkọ yii yoo ṣe itọsọna fun ọ lori fifi ẹya idurosinsin tuntun ti Nginx 1.10.0 sori Idawọle Red Hat tabi CentOS 7 lati awọn orisun, nitori awọn digi ibi ipamọ RHEL/CentOS 7 osise ko pese ipese alakomeji. Ti o ba fẹ yago fun fifi sori awọn orisun o le ṣafikun ibi ipamọ Nginx osise ki o fi sori ẹrọ package alakomeji (awọn ẹya ti o wa ni 1.9.x ) pẹlu iranlọwọ ti Yum Package Manager bi o ṣe han:
Lati jẹki ibi ipamọ yum osise yum fun RHEL/CentOS 7, ṣẹda faili kan /etc/yum.repos.d/nginx.repo pẹlu awọn akoonu wọnyi:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/ gpgcheck=0 enabled=1
Rọpo\"centos" pẹlu "rhel", da lori pinpin ti o nlo ati fi nginx sori ẹrọ pẹlu oluṣakoso package yum bi o ṣe han:
# yum install nginx
Pataki: Jọwọ ṣe akiyesi, atẹle atẹle awọn ibi ipamọ osise nginx yum loke yoo fun ọ ni ẹya atijọ ti nginx, ti o ba fẹ gaan kọ ẹya tuntun ti Nginx to ṣẹṣẹ, lẹhinna Mo daba fun ọ lati tẹle fifi sori orisun bi a ti han ni isalẹ.
Lilo akojọpọ awọn orisun ati fifi sori ẹrọ ni diẹ ninu awọn anfani, nitori otitọ pe o le fi ẹya tuntun ti o wa sori ẹrọ, o le ṣatunṣe iṣeto Nginx nipasẹ fifi kun tabi yiyọ awọn modulu, yi ọna eto fifi sori ẹrọ pada, tabi awọn eto pataki miiran, ni awọn ọrọ miiran, o ni a pari iṣakoso lori ilana fifi sori ẹrọ.
Igbesẹ 1: Gbaa lati ayelujara, ṣajọ ati Fi Nginx sii
1. Ṣaaju ki o to bẹrẹ akojọpọ Nginx ati ilana fifi sori ẹrọ rii daju pe o ni alakojọ C/C ++, PCRE (Perl ibaramu Awọn asọye deede), Zlib Ile-iwe Ikọpọ Ikọra ati OpenSSL (ti o ba pinnu lati ṣiṣe Nxing pẹlu atilẹyin SSL) awọn idii ti a fi sii lori ẹrọ rẹ nipa fifun pipaṣẹ wọnyi.
# 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. Nisisiyi lọ si oju-iwe osise Nginx ki o mu ẹya Stable tuntun ( nginx 1.10.0 ) ti o wa ni lilo pipaṣẹ wget , fa jade ni ile-iwe TAR ki o tẹ itọsọna Nginx jade, ni lilo awọn atẹle awọn 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. Igbese ti n tẹle ni ṣe ilana fifi sori ẹrọ Nginx. Lo faili tunto lati wo awọn aṣayan iṣeto ati awọn modulu ti o nilo fun ilana akopọ rẹ nipa lilo pipaṣẹ atẹle ki o rii daju pe o wa ni ọna nginx-1.6.0 /.
# ./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. Bayi o to akoko lati ṣajọ Nginx pẹlu awọn atunto rẹ pato ati ṣiṣe tabi awọn modulu alaabo. Fun ikẹkọ yii awọn modulu atẹle ati awọn alaye ni ibiti o ti lo, ṣugbọn o le tẹ akopọ si ohunkohun ti o baamu awọn aini rẹ.
- –user = nginx –group = nginx => olumulo eto ati ẹgbẹ ti Nginx yoo ṣiṣẹ bi.
- –prefix =/etc/nginx => itọsọna fun awọn faili olupin (faili nginx.conf ati awọn faili iṣeto miiran) - aiyipada ni/usr/agbegbe/itọsọna nginx.
- –sbin-path =/usr/sbin/nginx => Ibi faili ti o le ṣe si Nginx.
- –conf-path =/etc/nginx/nginx.conf => ṣeto orukọ fun faili iṣeto ni nginx.conf - o le yipada.
- –error-log-path =/var/log/nginx/error.log => n ṣeto ipo faili aṣiṣe aṣiṣe Nginx.
- –http-log-path =/var/log/nginx/access.log => ṣeto ipo faili faili wiwọle Nginx.
- –pid-path =/var/run/nginx.pid => ṣeto orukọ fun faili ID ilana akọkọ.
- –lock-path =/var/run/nginx.lock => ṣeto orukọ fun faili titiipa Nginx.
- –with-http_ssl_module => n jẹ ki kíkọ modulu HTTPS - ko ṣe nipasẹ aiyipada o nilo ibi-ikawe OpenSSL.
- –with-pcre => ṣeto ọna si awọn orisun ti ile-ikawe PCRE - ko ṣe nipasẹ aiyipada ati nilo ile-ikawe PCRE.
Lati wo atokọ ti gbogbo awọn modulu Nginx ṣabẹwo si oju-iwe wẹẹbu Nginx Wiki ni http://wiki.nginx.org/Modules.
Ti o ko ba nilo modulu kan pato ti o fi sii lori Nginx o le mu ki o pa pẹlu lilo pipaṣẹ atẹle.
--without-module_name
Bayi bẹrẹ lati ṣajọ Nginx nipasẹ ipinfunni aṣẹ atẹle, eyi ti yoo lo gbogbo awọn atunto ati awọn modulu ti a sọrọ loke (rii daju pe aṣẹ naa wa lori ila kan).
# ./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. Lẹhin ilana iṣakojọ jẹrisi gbogbo awọn ohun elo ti a nilo fun eto bi akopọ GNU C, PCRE ati awọn ile ikawe OpenSSL, o ṣẹda faili make.conf ati awọn abajade ti akopọ gbogbo awọn atunto.
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. Igbese ti o kẹhin ni lati kọ awọn alakomeji nipa lilo pipaṣẹ ṣe , eyiti o le gba akoko diẹ lati pari da lori awọn orisun ẹrọ rẹ, ki o fi Nginx sori ẹrọ rẹ pẹlu ṣe fi sori ẹrọ pipaṣẹ.
Ṣọra pe ṣe fifi sori ẹrọ nilo awọn anfani root lati ṣe fifi sori ẹrọ, nitorinaa ti o ko ba ibuwolu wọle pẹlu akọọlẹ gbongbo lo olumulo anfani pẹlu 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 \ ...
Igbesẹ 2: Tweak Nginx ati Ṣẹda INIT iwe afọwọkọ
7. Lẹhin ilana fifi sori ẹrọ ti pari pẹlu aṣeyọri ṣafikun nginx olumulo eto (pẹlu /ati be be/nginx/ bi itọsọna ile rẹ ati laisi ikarahun to wulo), olumulo ti Nginx yoo ṣiṣe bi nipasẹ ipinfunni aṣẹ atẹle.
# useradd -d /etc/nginx/ -s /sbin/nologin nginx
8. Nitori lori ilana akopọ a ti sọ tẹlẹ pe Nginx yoo ṣiṣẹ lati nginx olumulo eto, ṣii faili nginx.conf ki o yi alaye olumulo pada si nginx
# nano /etc/nginx/nginx.conf
Nibi wa ati yi olumulo pada ati, tun, ṣe igbasilẹ awọn alaye ipo gbongbo, pẹlu awọn aṣayan atẹle.
user nginx; location / { root /srv/www/html; autoindex on; index index.html index.htm;
9. Ṣaaju ki o to bẹrẹ Nginx, rii daju pe o ti ṣẹda ọna gbongbo iwe-ipamọ wẹẹbu, lẹhinna bẹrẹ nginx nipa lilo pipaṣẹ atẹle.
# mkdir -p /srv/www/html # /usr/sbin/nginx
Ti o ba fẹ ṣayẹwo boya Nginx n ṣiṣẹ ni lilo ikarahun ikarahun rẹ, ṣiṣe netstat pipaṣẹ lati ṣayẹwo awọn isopọ tẹtisi.
# netstat -tulpn | grep nginx
10. Lati ṣayẹwo rẹ lati inu eto latọna jijin, ṣafikun ofin ogiriina kan lati ṣii asopọ si ita ni Port 80 , ṣii ẹrọ lilọ kiri ayelujara kan ki o ṣe itọsọna URL si olupin IP Adirẹsi rẹ ni 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. Lati ṣakoso ilana Nginx lo awọn ofin wọnyi.
- nginx -V = ṣafihan awọn modulu Nginx ati awọn atunto
- nginx -h = awọn aṣayan iranlọwọ
- nginx = bẹrẹ ilana Nginx
- nginx -s duro = da ilana Nginx duro
- nginx -s reload = tun gbe ilana Nginx pada
# 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. Ti o ba nilo lati ṣakoso ilana Nginx daemon nipasẹ init RHEL/CentOS iwe afọwọkọ, ṣẹda faili nginx atẹle lori ọna eto /etc/init.d/ , ati, lẹhinna, o le lo iṣẹ tabi systemctl awọn aṣẹ lati ṣakoso ilana naa.
# nano /etc/init.d/nginx
Ṣafikun akoonu faili atẹle.
#!/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. Lẹhin ti a ṣẹda faili ingin Nginx, ṣe awọn igbanilaaye awọn ipaniyan ati ṣakoso daemon ni lilo awọn aṣayan aṣẹ isalẹ.
# chmod +x /etc/init.d/nginx # service nginx start|stop|restart|reload|force_reload|configtest|condrestart # systemctl start|stop|restart nginx
14. Ti o ba nilo lati mu eto Nginx ṣiṣẹ jakejado lo aṣẹ atẹle lati bẹrẹ ni akoko bata.
# chkconfig nginx on OR # systemctl enable nginx
Gbogbo ẹ niyẹn! Bayi o ni ẹya tuntun ti Nginx ti fi sori ẹrọ lori eto RHEL/CentOS 7 rẹ. Lori ẹkọ ti nbọ Emi yoo jiroro bi a ṣe le fi sori ẹrọ ati mu oluṣakoso ilana PHP-FPM ṣiṣẹ botilẹjẹpe Nginx FastCGI Gateway.
Ka Tun: Itọsọna Gbẹhin lati Ni aabo, Ikunkun ati Ṣiṣe Iṣe ti Server Nginx Web Server