RHEL/CentOS 7.0 çeşmelerinden Nginx 1.10.0 (Durnukly goýberiş) guruň we düzüň.
Nginx erkin açyk modul modeli, ýokary öndürijilikli, durnuklylyk, ýönekeý konfigurasiýa faýllary, asynkron arhitektura (hadysalara esaslanýan) we pes çeşmeler sebäpli häzirki wagtda açyk internet serwerlerinde iň çalt ösýän Webserver. ylgamak.
- RHEL 7.0-iň minimal gurnamasy
- RHEL 7.0-de işjeň RedHat abunalygy we ammarlary
- CentOS 7.0-iň minimal gurnamasy
- RHEL/CentOS 7.0-de statiki IP adresi düzüň
Bu gollanma, Red Hat Enterprise ýa-da CentOS 7-de Nginx 1.10.0 iň soňky durnukly wersiýasyny çeşmelerden gurnamaga ýol görkezer, sebäbi resmi RHEL/CentOS 7 ammar aýnalary ikilik paketini üpjün etmeýär. Çeşmeleri gurmakdan gaça durmak isleseňiz, resmi Nginx ammaryny goşup, ikilik paketini (elýeterli wersiýalary 1.9.x ) görkezip bilersiňiz, Yum Package Manager-iň kömegi bilen:
RHEL/CentOS 7 üçin nginx resmi ýum ammaryny açmak üçin aşakdaky mazmunly /etc/yum.repos.d/nginx.repo faýly dörediň:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/ gpgcheck=0 enabled=1
Ulanylýan paýlamaňyza baglylykda\sentos -y rhel bilen çalyşyň we görkezilişi ýaly yum paket dolandyryjysy bilen nginx guruň:
# yum install nginx
Üns beriň: aboveokardaky resmi nginx ýum ammarlaryna eýermek size nginx-iň köne wersiýasyny berer, eger hakykatdanam Nginx-iň iň soňky wersiýasyny gurmak isleseňiz, aşakda görkezilişi ýaly çeşme gurnamagy yzarlamagyňyzy maslahat berýärin.
Çeşmeleri düzmek we gurnamagyň käbir peýdalary bar, elýeterli iň soňky wersiýany gurup biljekdigiňiz sebäpli, modullary goşmak ýa-da aýyrmak, gurnama ulgamynyň ýoluny ýa-da beýleki möhüm sazlamalary üýtgedip, Nginx konfigurasiýasyny üýtgedip bilersiňiz, başgaça aýdanyňda, sizde a gurmak işine doly gözegçilik.
1-nji ädim: Nginx-i göçürip alyň, düzüň we guruň
1. Nginx düzmek we gurnamak işine başlamazdan ozal C/C ++ düzüjiniň, PCRE (Perl gabat gelýän yzygiderli aňlatmalar), Zlib gysyş kitaphanasy we OpenSSL bardygyna göz ýetiriň. (SSL goldawy bilen Nxing-i işletmek isleseňiz) aşakdaky buýrugy bermek bilen enjamyňyzda gurnalan paketler.
# 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. Indi Nginx resmi sahypasyna giriň we wget buýrugy ulanyp, iň soňky Durnukly wersiýany ( nginx 1.10.0 ) alyň, TAR arhiwini çykaryň we Nginx çykarylan katalogyna giriň aşakdaky buýruklar yzygiderliligi.
# 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. Indiki ädim, Nginx gurnama amalyny özleşdirmekdir. Aşakdaky buýrugy ulanyp, düzmek prosesi üçin zerur bolan konfigurasiýa opsiýalaryny we modullaryny göz öňüne getirmek üçin konfigurasiýa faýly ulanyň we nginx-1.6.0/ýolda bardygyňyzy anyklaň.
# ./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. Indi Nginx-i aýratyn konfigurasiýalaryňyz we işledilen ýa-da ýapylan modullar bilen düzmegiň wagty geldi. Bu gollanma üçin ulanylýan ýerlerde aşakdaky modullar we spesifikasiýalar bar, ýöne ýygyndyny zerurlyklaryňyza laýyklaşdyryp bilersiňiz.
- –user=nginx –group=nginx => Nginx-iň işlejek ulgam ulanyjysy we topary.
- –prefix =/etc/nginx => serwer faýllary üçin katalog (nginx.conf faýly we beýleki konfigurasiýa faýllary) - deslapky/usr/ýerli/nginx katalogy.
- –sbin-path =/usr/sbin/nginx => Nginx ýerine ýetirip boljak faýl ýerleşişi.
- –conf-path =/etc/nginx/nginx.conf => nginx.conf konfigurasiýa faýlynyň adyny kesgitleýär - üýtgedip bilersiňiz.
- errorror-log-path =/var/log/nginx/error.log => Nginx ýalňyş ýazgy faýlynyň ýerleşişini düzýär.
- –http-log-path =/var/log/nginx/access.log => Nginx giriş log faýlynyň ýerleşişini düzýär.
- idpid-path =/var/run/nginx.pid => esasy amal ID faýlynyň adyny kesgitleýär.
- –lock-path =/var/run/nginx.lock => Nginx gulp faýlynyň adyny düzýär.
- –with-http_ssl_module => HTTPS modulyny gurmaga mümkinçilik berýär - deslapky gurulmaýar we OpenSSL kitaphanasyny talap edýär.
- –with-pcre => PCRE kitaphanasynyň çeşmelerine ýol kesgitleýär - deslapky gurulmaýar we PCRE kitaphanasyny talap edýär.
Nginx modullarynyň sanawyny görmek üçin http://wiki.nginx.org/Modules sahypasyndaky Nginx Wiki web sahypasyna giriň.
Nginx-de gurnalan belli bir modul gerek däl bolsa, aşakdaky buýrugy ulanyp öçürip bilersiňiz.
--without-module_name
Indi ýokarda agzalan ähli konfigurasiýalary we modullary ulanjak aşakdaky buýrugy bermek bilen Nginx-i düzüp başlaň (buýrugyň bir setirde galýandygyna göz ýetiriň).
# ./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. Toplama prosesi GNU C düzüjisi, PCRE we OpenSSL kitaphanalary ýaly ähli ulgam zerur enjamlary barlandan soň, make.conf faýly döredýär we ähli konfigurasiýalaryň gysgaça mazmunyny çykarýar.
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. Iň soňky ädim, enjamyňyzyň çeşmelerine baglylykda gutarmak üçin birneme wagt alyp bilýän we gurnamak bilen ulgamyňyza Nginx gurmak üçin make buýrugyny ulanyp, ikilik gurmak. buýruk.
Gurmak üçin gurnamak kök aýratynlyklaryny talap edýär, şonuň üçin kök hasaby bilen girmedik bolsaňyz, sudo bilen artykmaç ulanyjy ulanyň.
# 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 \ ...
2-nji ädim: Nginx-i siňdiriň we INIT skriptini dörediň
7. Gurmak prosesi üstünlik bilen gutarandan soň, Nginx ulanyjysyny /etc/nginx/ bilen öý bukjasy hökmünde we ygtybarly gabyksyz) nginx ulgam ulanyjysyny goşuň. aşakdaky buýrugy bermek bilen işleýär.
# useradd -d /etc/nginx/ -s /sbin/nologin nginx
8. Sebäbi düzmek prosesinde Nginx-iň nginx ulgam ulanyjysyndan işlejekdigini kesgitledik, nginx.conf faýly açyň we ulanyjynyň beýanyny nginx .
# nano /etc/nginx/nginx.conf
Bu ýerde ulanyjyny tapyň we üýtgediň, şeýle hem aşakdaky opsiýalar bilen kök ýerleşiş jümlelerini resminama ediň.
user nginx; location / { root /srv/www/html; autoindex on; index index.html index.htm;
9. Nginx başlamazdan ozal web resminamasynyň kök ýoluny döredendigiňize göz ýetiriň, soňra aşakdaky buýrugy ulanyp nginx başlaň.
# mkdir -p /srv/www/html # /usr/sbin/nginx
Nginx-iň gabyk soragyňyzy ulanyp işleýändigini ýa-da ýokdugyny barlamak isleseňiz, diňlemek baglanyşyklaryny barlamak üçin netstat buýrugyny işlediň.
# netstat -tulpn | grep nginx
10. Uzakdaky ulgamdan barlamak üçin, Port 80 da daşarky birikmäni açmak üçin Firewall düzgünini goşuň, brauzeri açyň we serweriňiziň IP adresine göni salgysyny 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. Nginx amalyny dolandyrmak üçin aşakdaky buýruklary ulanyň.
- nginx -V =Nginx modullaryny we konfigurasiýalaryny görkezýär
- nginx -h =kömek opsiýalary
- nginx =Nginx prosesine başlaň
- nginx -s stop =Nginx prosesini duruzmak
- nginx -s täzeden ýüklemek =Nginx prosesi täzeden ýüklemek
# 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. Nginx daemon amalyny init RHEL/CentOS skripti arkaly dolandyrmak zerur bolsa, /etc/init.d/ ulgam ýolunda aşakdaky nginx faýly dörediň we, soň, amaly dolandyrmak üçin hyzmat ýa-da systemctl buýruklaryny ulanyp bilersiňiz.
# nano /etc/init.d/nginx
Aşakdaky faýl mazmunyny goşuň.
#!/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. Nginx init faýly döredilenden soň, ýerine ýetiriş rugsatlaryny goşuň we aşakdaky buýruk opsiýalaryny ulanyp daemony dolandyryň.
# chmod +x /etc/init.d/nginx # service nginx start|stop|restart|reload|force_reload|configtest|condrestart # systemctl start|stop|restart nginx
14. “Nginx” ulgamyny tutuşlygyna işletmeli bolsaňyz, başlamak üçin aşakdaky buýrugy ulanyň.
# chkconfig nginx on OR # systemctl enable nginx
Bu hemmesi! Indi RHEL/CentOS 7 ulgamyňyzda Nginx-iň iň soňky wersiýasy bar. Indiki sapakda, Nginx FastCGI şlýuzy bolsa-da, PHP-FPM amal dolandyryjysyny nädip gurmalydygyny we işletmelidigini ara alyp maslahatlaşaryn.
Şeýle hem okaň: Nginx web serweriniň howpsuzlygyny üpjün etmek, berkitmek we öndürijiligini gowulandyrmak üçin iň soňky gollanma