10 ຄຳ ສັ່ງ Nginx ທີ່ໃຊ້ຫຼາຍທີ່ສຸດທຸກໆ Linux ທີ່ຜູ້ໃຊ້ຕ້ອງຮູ້
Nginx (ອອກສຽງອອກສຽງ Engine x) ແມ່ນໂປແກຼມທີ່ບໍ່ເສຍຄ່າ, ເປີດ, ມີປະສິດຕິພາບສູງ, ສາມາດປັບຂະ ໜາດ ໄດ້, ເຊື່ອຖືໄດ້, ມີຄຸນລັກສະນະເຕັມຮູບແບບແລະນິຍົມ HTTP ແລະແບບໂຕ້ຕອບກັບຄືນ, ເຊີຟເວີຕົວແທນຈົດ ໝາຍ, ແລະເຊີຟເວີ TCP/UDP.
Nginx ແມ່ນເປັນທີ່ຮູ້ຈັກກັນດີ ສຳ ລັບການຕັ້ງຄ່າງ່າຍດາຍ, ແລະການໃຊ້ຊັບພະຍາກອນຕ່ ຳ ເນື່ອງຈາກມີປະສິດຕິພາບສູງ, ມັນຖືກ ນຳ ໃຊ້ເພື່ອໃຫ້ ກຳ ລັງການເຂົ້າຊົມເວັບໄຊທ໌ທີ່ມີການຈະລາຈອນສູງຫຼາຍໃນເວັບເຊັ່ນ GitHub, SoundCloud, Dropbox, Netflix, WordPress ແລະອື່ນໆ.
ໃນ ຄຳ ແນະ ນຳ ນີ້, ພວກເຮົາຈະອະທິບາຍບາງ ຄຳ ສັ່ງກ່ຽວກັບການບໍລິຫານບໍລິການ Nginx ທີ່ຖືກ ນຳ ໃຊ້ຫຼາຍທີ່ສຸດ, ໃນຖານະນັກພັດທະນາຫລືຜູ້ບໍລິຫານລະບົບ, ທ່ານຄວນຮັກສາຢູ່ປາຍນິ້ວມືຂອງທ່ານ. ພວກເຮົາຈະສະແດງ ຄຳ ສັ່ງ ສຳ ລັບທັງ Systemd ແລະ SysVinit.
ບັນຊີລາຍຊື່ຂອງ ຄຳ ສັ່ງທີ່ນິຍົມ Nginx ຕໍ່ໄປນີ້ຕ້ອງຖືກ ດຳ ເນີນການເປັນຜູ້ ນຳ ໃຊ້ຮາກຫຼື sudo ແລະຄວນເຮັດວຽກກ່ຽວກັບການແຈກຈ່າຍ Linux ແບບທັນສະ ໄໝ ໃດໆເຊັ່ນ CentOS, RHEL, Debian, Ubuntu ແລະ Fedora.
ຕິດຕັ້ງ Nginx Server
ການຕິດຕັ້ງເຄື່ອງແມ່ຂ່າຍເວັບໄຊຕ໌ Nginx, ໃຊ້ຕົວຈັດການຊຸດການແຈກຢາຍແບບເລີ່ມຕົ້ນຂອງທ່ານດັ່ງທີ່ສະແດງ.
$ sudo yum install epel-release && yum install nginx [On CentOS/RHEL] $ sudo dnf install nginx [On Debian/Ubuntu] $ sudo apt install nginx [On Fedora]
ກວດສອບ Nginx Version
ເພື່ອກວດເບິ່ງເວີຊັນຂອງເວັບເຊີຟເວີ Nginx ທີ່ຕິດຕັ້ງຢູ່ໃນລະບົບ Linux ຂອງທ່ານ, ໃຫ້ເຮັດຕາມ ຄຳ ສັ່ງຕໍ່ໄປນີ້.
$ nginx -v nginx version: nginx/1.12.2
ຄຳ ສັ່ງຂ້າງເທິງພຽງແຕ່ສະແດງຕົວເລກສະບັບ. ຖ້າທ່ານຕ້ອງການເບິ່ງຮູບແບບແລະການຕັ້ງຄ່າຕົວເລືອກຕ່າງໆແລ້ວໃຊ້ທຸງ -V
ຕາມທີ່ສະແດງ.
$ nginx -V
nginx version: nginx/1.12.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
ກວດເບິ່ງ Nginx Syntax ການຕັ້ງຄ່າ
ກ່ອນທີ່ທ່ານຈະເລີ່ມຕົ້ນການບໍລິການ Nginx, ທ່ານສາມາດກວດເບິ່ງວ່າ syntax ການຕັ້ງຄ່າຂອງມັນແມ່ນຖືກຕ້ອງຫຼືບໍ່. ນີ້ຈະເປັນປະໂຫຍດໂດຍສະເພາະຖ້າທ່ານໄດ້ປ່ຽນແປງຫລືເພີ່ມການຕັ້ງຄ່າ ໃໝ່ ໃນໂຄງສ້າງການຕັ້ງຄ່າທີ່ມີຢູ່ແລ້ວ.
ເພື່ອທົດສອບການຕັ້ງຄ່າ Nginx, ດຳ ເນີນການ ຄຳ ສັ່ງຕໍ່ໄປນີ້.
$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
ທ່ານສາມາດທົດສອບການຕັ້ງຄ່າ Nginx, ຖີ້ມມັນແລະອອກໂດຍໃຊ້ -T
ທຸງດັ່ງທີ່ສະແດງໄວ້.
$ sudo nginx -T
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful # configuration file /etc/nginx/nginx.conf: # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } ....
ເລີ່ມບໍລິການ Nginx
ເພື່ອເລີ່ມຕົ້ນການບໍລິການ Nginx, ດຳ ເນີນການ ຄຳ ສັ່ງຕໍ່ໄປນີ້. ໃຫ້ສັງເກດວ່າຂະບວນການນີ້ອາດຈະລົ້ມເຫລວຖ້າ syntax ການຕັ້ງຄ່າບໍ່ຖືກຕ້ອງ.
$ sudo systemctl start nginx #systemd OR $ sudo service nginx start #sysvinit
ເປີດໃຊ້ບໍລິການ Nginx
ຄໍາສັ່ງທີ່ຜ່ານມາພຽງແຕ່ເລີ່ມຕົ້ນການບໍລິການໃນເວລານີ້, ເພື່ອໃຫ້ມັນເລີ່ມຕົ້ນໂດຍອັດຕະໂນມັດໃນເວລາບູດ, ດໍາເນີນການຄໍາສັ່ງຕໍ່ໄປນີ້.
$ sudo systemctl enable nginx #systemd OR $ sudo service nginx enable #sysv init
ເລີ່ມບໍລິການ Nginx
ເພື່ອເລີ່ມການບໍລິການ Nginx, ເຊິ່ງເປັນການກະ ທຳ ທີ່ຈະຢຸດແລະຫຼັງຈາກນັ້ນກໍ່ເລີ່ມການບໍລິການ.
$ sudo systemctl restart nginx #systemd OR $ sudo service nginx restart #sysv init
ເບິ່ງສະຖານະບໍລິການຂອງ Nginx
ທ່ານສາມາດກວດເບິ່ງສະຖານະພາບຂອງການບໍລິການ Nginx ດັ່ງຕໍ່ໄປນີ້. ຄຳ ສັ່ງນີ້ສະແດງຂໍ້ມູນສະຖານະພາບເວລາແລ່ນກ່ຽວກັບການບໍລິການ.
$ sudo systemctl status nginx #systemd OR $ sudo service nginx status #sysvinit
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service. systemctl status nginx ● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2019-03-05 05:27:15 EST; 2min 59s ago Main PID: 31515 (nginx) CGroup: /system.slice/nginx.service ├─31515 nginx: master process /usr/sbin/nginx └─31516 nginx: worker process Mar 05 05:27:15 linux-console.net systemd[1]: Starting The nginx HTTP and reverse proxy server... Mar 05 05:27:15 linux-console.net nginx[31509]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok Mar 05 05:27:15 linux-console.net nginx[31509]: nginx: configuration file /etc/nginx/nginx.conf test is successful Mar 05 05:27:15 linux-console.net systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument Mar 05 05:27:15 linux-console.net systemd[1]: Started The nginx HTTP and reverse proxy server.
ໂຫຼດບໍລິການ Nginx ຄືນ ໃໝ່
ເພື່ອບອກໃຫ້ Nginx ໂຫລດການຕັ້ງຄ່າຂອງມັນ, ໃຫ້ໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.
$ sudo systemctl reload nginx #systemd OR $ sudo service nginx reload #sysvinit
ຢຸດບໍລິການ Nginx
ຖ້າທ່ານຕ້ອງການຢຸດບໍລິການ Nginx ດ້ວຍເຫດຜົນ ໜຶ່ງ ຫຼືເຫດຜົນອື່ນ, ໃຫ້ໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.
$ sudo systemctl stop nginx #systemd OR $ sudo service nginx stop #sysvinit
ສະແດງຄວາມຊ່ວຍເຫຼືອ ຄຳ ສັ່ງ Nginx
ເພື່ອໃຫ້ໄດ້ຄູ່ມືການອ້າງອີງງ່າຍໆຂອງທຸກ ຄຳ ສັ່ງແລະທາງເລືອກ Nginx, ໃຫ້ໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້.
$ systemctl -h nginx
systemctl [OPTIONS...] {COMMAND} ... Query or send control commands to the systemd manager. -h --help Show this help --version Show package version --system Connect to system manager -H --host=[[email ]HOST Operate on remote host -M --machine=CONTAINER Operate on local container -t --type=TYPE List units of a particular type --state=STATE List units with particular LOAD or SUB or ACTIVE state -p --property=NAME Show only properties by this name -a --all Show all loaded units/properties, including dead/empty ones. To list all units installed on the system, use the 'list-unit-files' command instead. -l --full Don't ellipsize unit names on output -r --recursive Show unit list of host and local containers --reverse Show reverse dependencies with 'list-dependencies' --job-mode=MODE Specify how to deal with already queued jobs, when queueing a new job --show-types When showing sockets, explicitly show their type -i --ignore-inhibitors ...
ທ່ານອາດຈະຢາກອ່ານບົດຄວາມທີ່ກ່ຽວຂ້ອງກັບ Nginx ຕໍ່ໄປນີ້.
<
ດຽວນີ້ ໝົດ ແລ້ວ! ໃນຄູ່ມືນີ້, ພວກເຮົາໄດ້ອະທິບາຍບາງ ຄຳ ສັ່ງກ່ຽວກັບການຄຸ້ມຄອງບໍລິການ Nginx ທີ່ຖືກ ນຳ ໃຊ້ຫຼາຍທີ່ສຸດທີ່ທ່ານຄວນຮູ້, ລວມທັງການເລີ່ມຕົ້ນ, ເປີດໃຊ້ງານ, ເລີ່ມຕົ້ນ ໃໝ່ ແລະຢຸດໃຊ້ Nginx. ຖ້າທ່ານມີ ຄຳ ຖາມເພີ່ມເຕີມຫຼື ຄຳ ຖາມທີ່ຕ້ອງຖາມ, ໃຊ້ແບບຟອມ ຄຳ ເຫັນຂ້າງລຸ່ມນີ້.