ຕິດຕັ້ງແລະລວບລວມ "Nginx 1.10.0" (ປ່ອຍແບບຄົງທີ່) ຈາກແຫຼ່ງຕ່າງໆໃນ RHEL/CentOS 7.0


Nginx ແມ່ນ Webserver ທີ່ມີການຂະຫຍາຍຕົວໄວທີ່ສຸດໃນປະຈຸບັນນີ້ໃນອິນເຕີເນັດທີ່ສາມາດປະເຊີນ ໜ້າ ກັບເຊີບເວີໄດ້ເນື່ອງຈາກຮູບແບບໂມດູນເປີດແບບເປີດຟຣີ ແລ່ນ.

<

  • ການຕິດຕັ້ງ ໜ້ອຍ ທີ່ສຸດຂອງ RHEL 7.0
  • ການຈອງແລະການ ນຳ ໃຊ້ RedHat ທີ່ໃຊ້ໃນ RHEL 7.0
  • <

  • ການຕິດຕັ້ງ ໜ້ອຍ ທີ່ສຸດຂອງ CentOS 7.0
  • <

  • ຕັ້ງ IP Address Static ໃນ RHEL/CentOS 7.0
  • ຄຳ ແນະ ນຳ ນີ້ຈະແນະ ນຳ ທ່ານກ່ຽວກັບການຕິດຕັ້ງລຸ້ນ ໃໝ່ ທີ່ມີຄວາມ ໝັ້ນ ຄົງຫຼ້າສຸດຂອງ Nginx 1.10.0 ກ່ຽວກັບ Red Hat Enterprise ຫຼື CentOS 7 ຈາກແຫຼ່ງຕ່າງໆ, ເພາະວ່າຫໍສະ ໝຸດ RHEL/CentOS 7 ຢ່າງເປັນທາງການບໍ່ໄດ້ສະ ໜອງ ຊຸດໄບນາລີ. ຖ້າທ່ານຕ້ອງການຫລີກລ້ຽງການຕິດຕັ້ງແຫຼ່ງຂໍ້ມູນທ່ານສາມາດເພີ່ມບ່ອນເກັບຂໍ້ມູນ Nginx ຢ່າງເປັນທາງການແລະຕິດຕັ້ງຊຸດຖານສອງ (ແບບທີ່ມີຢູ່ແມ່ນ 1.9.x ) ໂດຍການຊ່ວຍເຫຼືອຂອງຜູ້ຈັດການ Yum Package ດັ່ງທີ່ສະແດງ:

    ເພື່ອເປີດໃຊ້ repository yum official ຂອງ nginx ສຳ ລັບ RHEL/CentOS 7, ສ້າງ file /etc/yum.repos.d/nginx.repo ດ້ວຍເນື້ອໃນຕໍ່ໄປນີ້:

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

    ປ່ຽນແທນ“ ເຊັນເຊີ້” ໂດຍ“ rhel”, ຂື້ນກັບການແຈກຈ່າຍທີ່ທ່ານ ກຳ ລັງໃຊ້ແລະຕິດຕັ້ງ nginx ກັບຜູ້ຈັດການ package yum ດັ່ງທີ່ສະແດງ:

    # yum install nginx
    

    ສິ່ງ ສຳ ຄັນ: ກະລຸນາຮັບຊາບ, ປະຕິບັດຕາມຂ້າງເທິງຂອງຫໍສະ ໝຸດ nginx ທີ່ເປັນທາງການຈະເຮັດໃຫ້ທ່ານມີ Nginx ລຸ້ນເກົ່າ, ຖ້າທ່ານຕ້ອງການກໍ່ສ້າງ Nginx ລຸ້ນ ໃໝ່ ຫຼ້າສຸດ, ຂ້າພະເຈົ້າຂໍແນະ ນຳ ໃຫ້ທ່ານຕິດຕາມແຫຼ່ງຕິດຕັ້ງດັ່ງທີ່ສະແດງຢູ່ຂ້າງລຸ່ມ.

    ການ ນຳ ໃຊ້ການລວບລວມແລະການຕິດຕັ້ງແຫຼ່ງຂໍ້ມູນມີປະໂຫຍດບາງຢ່າງ, ເນື່ອງຈາກວ່າທ່ານສາມາດຕິດຕັ້ງເວີຊັນລ້າສຸດທີ່ມີຢູ່, ທ່ານສາມາດປັບແຕ່ງການຕັ້ງຄ່າ Nginx ໂດຍການເພີ່ມຫລືຖອດໂມດູນ, ປ່ຽນເສັ້ນທາງລະບົບການຕິດຕັ້ງ, ຫຼືການຕັ້ງຄ່າທີ່ ສຳ ຄັນອື່ນໆ, ທ່ານເວົ້າວ່າ: ການຄວບຄຸມ ສຳ ເລັດຂັ້ນຕອນການຕິດຕັ້ງ.

    ຂັ້ນຕອນທີ 1: ດາວໂຫລດ, ລວບລວມແລະຕິດຕັ້ງ Nginx

    1. ກ່ອນທີ່ຈະເລີ່ມຕົ້ນການລວບລວມແລະການຕິດຕັ້ງ Nginx ໃຫ້ແນ່ໃຈວ່າທ່ານມີ C/C ++ compiler, PCRE (Perl Compatible ປົກກະຕິການສະແດງອອກ), Zlib ຫໍສະ ໝຸດ ອັດແລະ OpenSSL (ຖ້າທ່ານຕັ້ງໃຈແລ່ນ Nxing ດ້ວຍການສະ ໜັບ ສະ ໜູນ SSL) ການຕິດຕັ້ງຢູ່ໃນເຄື່ອງຂອງທ່ານໂດຍການອອກ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

    # 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. ຕອນນີ້ໄປທີ່ ໜ້າ ເວັບທາງການຂອງ Nginx ແລະຈັບເອົາຮຸ່ນ Stable ລ້າສຸດ ( nginx 1.10.0 ) ທີ່ມີຢູ່ໂດຍໃຊ້ wget ຄຳ ສັ່ງ, ສະກັດເອົາຮວບຮວມ TAR ແລະເຂົ້າໄປໃນແຟ້ມທີ່ຖືກສະກັດຈາກ 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]
    

    3. ຂັ້ນຕອນຕໍ່ໄປແມ່ນການປັບແຕ່ງຂັ້ນຕອນການຕິດຕັ້ງ Nginx. ໃຊ້ແຟ້ມ ຕັ້ງຄ່າ ເພື່ອເບິ່ງເຫັນຕົວເລືອກການຕັ້ງຄ່າແລະໂມດູນທີ່ ຈຳ ເປັນ ສຳ ລັບຂັ້ນຕອນການລວບລວມຂໍ້ມູນຂອງທ່ານໂດຍໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້ແລະໃຫ້ແນ່ໃຈວ່າທ່ານຢູ່ໃນເສັ້ນທາງ 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. ດຽວນີ້ເຖິງເວລາທີ່ຈະລວບລວມ Nginx ກັບການຕັ້ງຄ່າສະເພາະຂອງທ່ານແລະໂມດູນທີ່ເປີດໃຊ້ງານຫຼືພິການ. ສຳ ລັບ ຄຳ ແນະ ນຳ ນີ້ມີໂມດູນແລະວິຊາສະເພາະຕໍ່ໄປນີ້ທີ່ຖືກ ນຳ ໃຊ້, ແຕ່ທ່ານສາມາດປັບແຕ່ງການລວບລວມຂໍ້ມູນໃຫ້ ເໝາະ ສົມກັບຄວາມຕ້ອງການຂອງທ່ານ.

    <

  • –user = nginx –group = nginx => ຜູ້ໃຊ້ລະບົບແລະກຸ່ມທີ່ Nginx ຈະໃຊ້ເປັນ.
  • –prefix =/etc/nginx => ໄດເລກະທໍລີ ສຳ ລັບໄຟລ໌ເຊີບເວີ (ໄຟລ໌ nginx.conf ແລະແຟ້ມການຕັ້ງຄ່າອື່ນໆ) - ຄ່າເລີ່ມຕົ້ນແມ່ນ/usr/local/nginx.
  • –sbin-path =/usr/sbin/nginx => ສະຖານທີ່ແຟ້ມ Nginx ທີ່ໃຊ້ງານໄດ້.
  • –conf-path =/etc/nginx/nginx.conf => ກຳ ນົດຊື່ ສຳ ລັບເອກະສານການຕັ້ງຄ່າ nginx.conf - ທ່ານສາມາດປ່ຽນມັນໄດ້.
  • –error-log-path =/var/log/nginx/error.log => ກຳ ນົດສະຖານທີ່ແຟ້ມຂໍ້ຜິດພາດຂອງ Nginx.
  • –http-log-path =/var/log/nginx/access.log => ກຳ ນົດສະຖານທີ່ແຟ້ມຂໍ້ມູນການເຂົ້າເຖິງ Nginx.
  • –pid-path =/var/run/nginx.pid => ຕັ້ງຊື່ ສຳ ລັບເອກະສານ ID ຂອງຂະບວນການຕົ້ນຕໍ.
  • –lock-path =/var/run/nginx.lock => ຕັ້ງຊື່ ສຳ ລັບເອກະສານລັອກ Nginx.
  • –with-http_ssl_module => ຊ່ວຍໃຫ້ການກໍ່ສ້າງໂມດູນ HTTPS - ບໍ່ໄດ້ສ້າງໂດຍຄ່າເລີ່ມຕົ້ນແລະຕ້ອງການຫ້ອງສະ ໝຸດ OpenSSL.
  • –with-pcre => ກຳ ນົດເສັ້ນທາງສູ່ແຫຼ່ງທີ່ມາຂອງຫໍສະ ໝຸດ PCRE - ບໍ່ໄດ້ສ້າງໂດຍຄ່າເລີ່ມຕົ້ນແລະຕ້ອງການຫ້ອງສະ ໝຸດ PCRE.
  • ເພື່ອເບິ່ງລາຍຊື່ຂອງໂມດູນ Nginx ທັງ ໝົດ ເຂົ້າເບິ່ງ ໜ້າ ເວັບໄຊທ໌ Nginx Wiki ທີ່ http://wiki.nginx.org/Modules.

    ຖ້າທ່ານບໍ່ ຈຳ ເປັນຕ້ອງມີໂມດູນສະເພາະທີ່ຕິດຕັ້ງຢູ່ໃນ 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
    ...
    

    5. ຫຼັງຈາກຂະບວນການລວບລວມຂໍ້ມູນກວດສອບລະບົບສາທາລະນູປະໂພກທັງ ໝົດ ທີ່ຕ້ອງການເຊັ່ນຄອມພີວເຕີ້ GNU C, ຄອມພີວເຕີ້ PCRE ແລະ OpenSSL, ມັນຈະສ້າງເອກະສານ make.conf ແລະສະຫຼຸບສັງລວມການຕັ້ງຄ່າທັງ ໝົດ.

    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. ຂັ້ນຕອນສຸດທ້າຍແມ່ນການກໍ່ສ້າງໄບນາລີໂດຍໃຊ້ ຄຳ ສັ່ງ ສ້າງ ເຊິ່ງໃຊ້ເວລາບາງເວລາ ສຳ ເລັດໂດຍອີງຕາມຊັບພະຍາກອນຂອງເຄື່ອງຂອງທ່ານ, ແລະຕິດຕັ້ງ Nginx ໃນລະບົບຂອງທ່ານດ້ວຍ ສ້າງຕິດຕັ້ງ ຄຳ ສັ່ງ.

    ລະວັງວ່າ ການຕິດຕັ້ງຮຽກຮ້ອງໃຫ້ມີສິດທິພິເສດຮາກ ເພື່ອ ດຳ ເນີນການຕິດຕັ້ງ, ສະນັ້ນຖ້າທ່ານບໍ່ໄດ້ເຂົ້າສູ່ລະບົບກັບບັນຊີຮາກໃຊ້ຜູ້ໃຊ້ສິດທິພິເສດກັບ 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 \
    ...
    

    ຂັ້ນຕອນທີ 2: Tweak Nginx ແລະສ້າງ INIT Script

    7. ຫຼັງຈາກຂັ້ນຕອນການຕິດຕັ້ງ ສຳ ເລັດແລ້ວດ້ວຍຄວາມ ສຳ ເລັດເພີ່ມຜູ້ໃຊ້ລະບົບ nginx (ດ້ວຍ /etc/nginx/ ເປັນບ່ອນຢູ່ເຮືອນຂອງລາວແລະບໍ່ມີຫອຍທີ່ຖືກຕ້ອງ), ຜູ້ໃຊ້ທີ່ Nginx ຈະ ດຳ ເນີນການຄືກັບການອອກ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

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

    8. ຍ້ອນວ່າໃນຂັ້ນຕອນການລວບລວມຂໍ້ມູນທີ່ພວກເຮົາໄດ້ ກຳ ນົດໄວ້ວ່າ Nginx ຈະແລ່ນຈາກ nginx ຜູ້ໃຊ້ລະບົບ, ເປີດ nginx.conf ແຟ້ມແລະປ່ຽນ ຄຳ ຖະແຫຼງຜູ້ໃຊ້ເປັນ nginx >.

    # nano /etc/nginx/nginx.conf

    ທີ່ນີ້ຊອກຫາສະຖານທີ່ແລະປ່ຽນຜູ້ໃຊ້ແລະ, ຍັງ, ຂຽນເອກະສານລາຍງານສະຖານທີ່ຮາກ, ໂດຍມີຕົວເລືອກຕໍ່ໄປນີ້.

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

    9. ກ່ອນທີ່ຈະເລີ່ມ Nginx, ຮັບປະກັນວ່າທ່ານໄດ້ສ້າງເສັ້ນທາງຮາກຂອງເອກະສານເວັບແລ້ວກໍ່ເລີ່ມ nginx ໂດຍໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

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

    ຖ້າທ່ານຕ້ອງການກວດສອບວ່າ Nginx ກຳ ລັງເຮັດວຽກຢູ່ໂດຍໃຊ້ ຄຳ ສັ່ງຫອຍຂອງທ່ານ, ດຳ ເນີນການ ຄຳ ສັ່ງ netstat ເພື່ອກວດສອບການເຊື່ອມຕໍ່ຟັງ.

    # netstat -tulpn | grep nginx

    10. ເພື່ອກວດສອບມັນຈາກລະບົບຫ່າງໄກສອກຫຼີກ, ເພີ່ມກົດລະບຽບຂອງ Firewall ເພື່ອເປີດການເຊື່ອມຕໍ່ກັບທາງນອກຂອງ Port 80 , ເປີດ browser ແລະ URL ໂດຍກົງໃສ່ IP address ຂອງ server ຂອງທ່ານທີ່ 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 ໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

    <

  • nginx -V = ສະແດງໂມດູນແລະການຕັ້ງຄ່າ Nginx
  • nginx -h = ຕົວເລືອກຊ່ວຍເຫຼືອ
  • nginx = ເລີ່ມຕົ້ນຂັ້ນຕອນ Nginx
  • nginx -s stop = ຢຸດ Nginx ຂັ້ນຕອນ
  • nginx -s reload = ໂຫຼດຂະບວນການ 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. ຖ້າທ່ານຕ້ອງການຈັດການຂັ້ນຕອນຂອງ Nginx daemon ໂດຍຜ່ານອັກສອນ init RHEL/CentOS, ສ້າງໄຟລ໌ nginx ຕໍ່ໄປນີ້ໃນເສັ້ນທາງລະບົບ /etc/init.d/ , ແລະ, ຫຼັງຈາກນັ້ນ, ທ່ານສາມາດໃຊ້ ຄຳ ສັ່ງ ບໍລິການ ຫຼື systemctl ເພື່ອຈັດການຂັ້ນຕອນ.

    # 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

    13. ຫຼັງຈາກ Nginx init file ຖືກສ້າງຂື້ນ, ໃຫ້ອະນຸຍາດການປະຕິບັດແລະຈັດການ daemon ໂດຍໃຊ້ຕົວເລືອກ ຄຳ ສັ່ງດ້ານລຸ່ມ.

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

    14. ຖ້າທ່ານຕ້ອງການເປີດໃຊ້ລະບົບ Nginx ໂດຍໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້ເພື່ອເລີ່ມຕົ້ນໃນເວລາບູດ.

    # chkconfig nginx on
    
    OR
    
    # systemctl enable nginx

    ຫມົດເທົ່ານີ້! ຕອນນີ້ທ່ານໄດ້ຕິດຕັ້ງ Nginx ລຸ້ນລ້າສຸດໃນລະບົບ RHEL/CentOS 7 ຂອງທ່ານ. ໃນບົດແນະ ນຳ ຕໍ່ໄປຂ້ອຍຈະປຶກສາຫາລືກ່ຽວກັບວິທີຕິດຕັ້ງແລະເປີດໃຊ້ຜູ້ຈັດການຂັ້ນຕອນຂອງ PHP-FPM ເຖິງວ່າ Nginx FastCGI Gateway

    ອ່ານອີກ: ຄູ່ມືສຸດທ້າຍໃນການຮັກສາຄວາມປອດໄພ, ຄວາມແຂງກະດ້າງແລະປັບປຸງການເຮັດວຽກຂອງ Nginx Web Server