RHEL/CentOS 7.0 -ב תורוקממ (ביצי רורחש) "Nginx 1.10.0" תא ביכרהו ןקתה
Nginx ץורל םישרדנה םיכומנה םיבאשמהו (םיעוריא ענומ) תינורכניסא הרוטקטיכרא ,םיטושפ הרוצת יצבק ,תוביצי ,םיהובג םיעוציב ,םניחב חותפ דוק ירלודומ לדומ לשב טנרטניאל םינופה םיתרשב םויכ רת
:גצומכ Yum לש הליבחה להנמ תרזעב ( 1.9.x ןה תונימזה תואסרגה) תיראניבה הליבחה תא ןיקתהלו Nginx לש ימשר רגאמ ףיסוהל לכות תורוקמ תנקתהמ ענמיהל ךנוצרב םא .תיראניב הליבח תוקפסמ ןניא RHEL
:אבה ןכותה םע etc/yum.repos.d/nginx.repo/ ץבוק רוצ ,RHEL/CentOS 7 רובע nginx לש ימשר םאי רגאמ רשפאל ידכ
[nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/ gpgcheck=0 enabled=1
:גצומכ yum לש תוליבחה להנמ םע nginx תא ןקתהו שמתשמ התא הבש הצפהל םאתהב ,"rhel" -ב "centos"\תא ףלחה
# yum install nginx
.ןלהל גצומכ רוקמה תנקתה רחא בוקעל ךל ץילממ ינא זא ,Nginx לש הנורחאה הסרגה תא תונבל הצור תמאב התא םא ,nginx לש רתוי הנשי הסרג ךל ןתיי ליעל םיימשר nginx yum ירגאמ תובקעב ,בל םיש :בושח
.הנקתהה ךילהתב האלמ הטילש ךל שי ,תורחא םילימב ,תורחא תובושח תורדגה וא הנקתהה תכרעמ ביתנ יוניש ,םילודומ לש הרסה וא הפסוה ידי לע Nginx תרוצת תא תונשל לוכי התא ,הנימזה הנורחאה הסרגה תא ןיקתהל
Nginx תא ןקתהו רודיה ,דרוה :1 בלש
.האבה הדוקפה תקפנה ידי לע ךלש בשחמב תונקתומה תוליבח (SSL תכימת םע Nxing ץירהל ךתנווכב םא) OpenSSL ו הסיחד תיירפס C/C ++ compiler, PCRE (Perl Compatible Expressions Ex
# 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 ...
.אבה תודוקפה ףצר תועצמאב Nginx הצלוחש היירפסב ןזהו TAR -ה ןויכרא תא ץליח , wget הדוקפה תועצמאב הנימזה Stable ( nginx 1.10.0 ) לש הנורחאה הסרגה תא חקו Nginx לש ימשרה ףדל רובע
# 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]
.nginx-1.6.0/path -ב אצמנ התאש אדוו האבה הדוקפה תועצמאב ךלש היצליפמוקה ךילהתל םישורדה םילודומו הרוצת תויורשפא ןיימדל ידכ רדגה ץבוקב שמתשה .Nginx לש הנקתהה ךילהת לש תישיא המאתה
# ./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 ...
.ךלש םיכרצל םיאתמש המ לכל ףסואה תא תונשל ךתורשפאב ךא ,םיאבה טרפמבו םילודומב שומיש השענ וז הכרדהל .םיתבשומ וא םילעפומ םילודומו ךלש תויפיצפסה תורוצתה םע Nginx תא ףוסאל ןמזה עיגה וישכע .4
.http://wiki.nginx.org/Modules תבותכב Nginx Wiki לש טנרטניאה ףדב רקב Nginx לש םילודומה לכ לש המישרב הייפצל
.האבה הדוקפה תועצמאב ותוא תיבשהל לכות ,Nginx -ב ןקתומה יפיצפס לודומל קוקז ךניא םא
--without-module_name
.(תחא הרושב תראשנ הדוקפהש אדו) ליעל ונודנש םילודומהו תורוצתה לכב שמתשתש ,האבה הדוקפה תקפנה ידי לע Nginx תא לפמקל לחתה וישכע
# ./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 ...
.תורוצתה לכ לש םוכיס קיפמו make.conf ץבוקה תא רצוי אוה ,OpenSSL -ו GNU C, PCRE רדהמ ומכ תכרעמל םישרדנה תורישה ילכ לכ תא תמאמ ףסואה ךילהתש רחאל .5
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"
.הדוקפ make install םע ךלש תכרעמב Nginx תא ןיקתהלו ,ךלש בשחמה יבאשמל םאתהב םויסל ןמז תצק תחקל הלוכיש , make הדוקפה תועצמאב תויראניבה תיינב אוה ןורחאה בלשה .6
. 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 \ ...
INIT טפירקס רוצו Nginx תא ןנווכ :2 בלש
.האבה הדוקפה תקפנה ידי לע ומכ לעפי Nginx -ש שמתשמה ,(תיקוח תפטעמ אללו ולש תיבה תיירפסכ /etc/nginx/ םע) תכרעמ שמתשמ nginx ףסוה החלצהב םייתסה הנקתהה ךילהתש רחאל .7
# useradd -d /etc/nginx/ -s /sbin/nologin nginx
.< b> nginx ל שמתשמה תרהצה תא הנשו nginx.conf ץבוקה תא חתפ , nginx שמתשממ לעפת Nginx יכ ונייצ היצליפמוקה ךילהתבש ןוויכמ .8
# nano /etc/nginx/nginx.conf
.תואבה תויורשפאה םע ,שרוש םוקימ תורהצה דעת םגו שמתשמה תא הנשו רתא ןאכ
user nginx; location / { root /srv/www/html; autoindex on; index index.html index.htm;
.האבה הדוקפה תועצמאב nginx תא לחתה זאו ,טנרטניאה ךמסמ לש סיסבה ביתנ תא תרציש אדוו ,Nginx תא ליחתתש ינפל .9
# mkdir -p /srv/www/html # /usr/sbin/nginx
.הנזאה ירוביח תמאל ידכ netstat הדוקפה תא לעפה ,ךלש זגפה תדוקפה תועצמאב לעופ Nginx םא קודבל הצור התא םא
# netstat -tulpn | grep nginx
http:// server_IP ב ךלש תרשה לש IP -ה תבותכל הרישי רתא תבותכו ןפדפד חתפ , 80 האיציב ינוציח רוביח תחיתפל שא תמוח ללכ ףסוה ,תקחורמ תכרעממ תאז תמאל ידכ .10
# firewall-cmd --add-service=http ## For on-fly rule # firewall-cmd --permanent --add-service=http ## For permanent rule # systemctl restart firewalld
.תואבה תודוקפב שמתשה Nginx ךילהת תא להנל ידכ .11
# 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
.ךילהתה לוהינל systemctl וא תוריש תודוקפב שמתשהל ךתורשפאב ,ןכמ רחאל , /etc/init.d/ תכרעמה ביתנב אבה nginx -ה ץבוק תא רוצ ,
# nano /etc/init.d/nginx
.אבה ץבוקה ןכות תא ףסוה
#!/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
.ןלהלש הדוקפה תויורשפא תועצמאב ןומדה תא להנהו עוציב תואשרה ריצ ,Nginx -ה ץבוק תריצי רחאל .13
# chmod +x /etc/init.d/nginx # service nginx start|stop|restart|reload|force_reload|configtest|condrestart # systemctl start|stop|restart nginx
.לוחתאה ןמזב ליחתהל ידכ האבה הדוקפב שמתשה ,Nginx תכרעמ תא ליעפהל ךילע םא .14
# chkconfig nginx on OR # systemctl enable nginx
.Nginx FastCGI Gateway תורמל PHP-FPM םיכילהתה להנמ תא ליעפהלו ןיקתהל דציכ ןודא אבה ךירדמב .Nginx לש הנורחאה הסרגה RHEL/CentOS 7 תכרעמב תנקתומ תעכ !לכה הז
Nginx טנרטניאה תרש לש םיעוציב רפשלו חישקהל ,חטבאל יביטמיטלואה ךירדמה :םג ארק