ഓരോ ലിനക്സ് ഉപയോക്താവും അറിഞ്ഞിരിക്കേണ്ട ഏറ്റവും കൂടുതൽ ഉപയോഗിക്കുന്ന Nginx കമാൻഡുകൾ


Nginx (Engine x എന്ന് ഉച്ചരിക്കുന്നത്) ഒരു സ്വതന്ത്ര, ഓപ്പൺ സോഴ്uസ്, ഉയർന്ന-പ്രകടനം, സ്കേലബിൾ, വിശ്വസനീയമായ, പൂർണ്ണ ഫീച്ചർ ഉള്ളതും ജനപ്രിയമായ HTTP, റിവേഴ്സ് പ്രോക്സി സെർവർ, ഒരു മെയിൽ പ്രോക്സി സെർവർ, ഒരു ജനറിക് TCP/UDP പ്രോക്സി സെർവർ എന്നിവയാണ്.

Nginx അതിന്റെ ലളിതമായ കോൺഫിഗറേഷനും ഉയർന്ന പ്രകടനം കാരണം കുറഞ്ഞ വിഭവ ഉപഭോഗത്തിനും പേരുകേട്ടതാണ്, GitHub, SoundCloud, Dropbox, Netflix, WordPress തുടങ്ങി നിരവധി ഉയർന്ന ട്രാഫിക് സൈറ്റുകൾ വെബിൽ പവർ ചെയ്യാൻ ഇത് ഉപയോഗിക്കുന്നു.

ഈ ഗൈഡിൽ, ഒരു ഡവലപ്പർ അല്ലെങ്കിൽ സിസ്റ്റം അഡ്മിനിസ്ട്രേറ്റർ എന്ന നിലയിൽ, നിങ്ങളുടെ വിരൽത്തുമ്പിൽ സൂക്ഷിക്കേണ്ട ഏറ്റവും സാധാരണയായി ഉപയോഗിക്കുന്ന Nginx സേവന മാനേജുമെന്റ് കമാൻഡുകൾ ഞങ്ങൾ വിശദീകരിക്കും. Systemd, SysVinit എന്നിവയ്uക്കുള്ള കമാൻഡുകൾ ഞങ്ങൾ കാണിക്കും.

താഴെപ്പറയുന്ന Nginx ജനപ്രിയ കമാൻഡുകൾ എല്ലാം ഒരു റൂട്ട് അല്ലെങ്കിൽ സുഡോ ഉപയോക്താവായി എക്സിക്യൂട്ട് ചെയ്യണം കൂടാതെ CentOS, RHEL, Debian, Ubuntu, Fedora തുടങ്ങിയ ഏത് ആധുനിക ലിനക്സ് വിതരണത്തിലും പ്രവർത്തിക്കണം.

Nginx സെർവർ ഇൻസ്റ്റാൾ ചെയ്യുക

Nginx വെബ് സെർവർ ഇൻസ്റ്റാൾ ചെയ്യാൻ, കാണിച്ചിരിക്കുന്നതുപോലെ നിങ്ങളുടെ ഡിഫോൾട്ട് ഡിസ്ട്രിബ്യൂഷൻ പാക്കേജ് മാനേജർ ഉപയോഗിക്കുക.

$ sudo yum install epel-release && yum install nginx   [On CentOS/RHEL]
$ sudo dnf install nginx                               [On Fedora]
$ sudo apt install nginx                               [On Debian/Ubuntu]

Nginx പതിപ്പ് പരിശോധിക്കുക

നിങ്ങളുടെ Linux സിസ്റ്റത്തിൽ ഇൻസ്റ്റാൾ ചെയ്ത Nginx വെബ് സെർവറിന്റെ പതിപ്പ് പരിശോധിക്കുന്നതിന്, ഇനിപ്പറയുന്ന കമാൻഡ് പ്രവർത്തിപ്പിക്കുക.

$ 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 കോൺഫിഗറേഷൻ സിന്റാക്സ് പരിശോധിക്കുക

നിങ്ങൾ യഥാർത്ഥത്തിൽ Nginx സേവനം ആരംഭിക്കുന്നതിന് മുമ്പ്, അതിന്റെ കോൺഫിഗറേഷൻ വാക്യഘടന ശരിയാണോ എന്ന് നിങ്ങൾക്ക് പരിശോധിക്കാം. നിലവിലുള്ള കോൺഫിഗറേഷൻ ഘടനയിൽ നിങ്ങൾ മാറ്റങ്ങൾ വരുത്തുകയോ ഒരു പുതിയ കോൺഫിഗറേഷൻ ചേർക്കുകയോ ചെയ്തിട്ടുണ്ടെങ്കിൽ ഇത് പ്രത്യേകിച്ചും ഉപയോഗപ്രദമാണ്.

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 സേവനം ആരംഭിക്കുന്നതിന്, ഇനിപ്പറയുന്ന കമാൻഡ് പ്രവർത്തിപ്പിക്കുക. കോൺഫിഗറേഷൻ വാക്യഘടന ശരിയല്ലെങ്കിൽ ഈ പ്രക്രിയ പരാജയപ്പെട്ടേക്കാം എന്നത് ശ്രദ്ധിക്കുക.

$ 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 അനുബന്ധ ലേഖനങ്ങളും വായിക്കാൻ നിങ്ങൾ ആഗ്രഹിച്ചേക്കാം.

  1. Nginx വെബ് സെർവറിന്റെ പ്രകടനം സുരക്ഷിതമാക്കാനും കഠിനമാക്കാനും മെച്ചപ്പെടുത്താനുമുള്ള ആത്യന്തിക ഗൈഡ്
  2. ആംപ്ലിഫൈ - NGINX മോണിറ്ററിംഗ് എളുപ്പമാക്കി
  3. ngxtop – Linux-ൽ Nginx ലോഗ് ഫയലുകൾ തത്സമയം നിരീക്ഷിക്കുക
  4. വെർച്വൽ ഹോസ്റ്റുകളും SSL സർട്ടിഫിക്കറ്റും ഉപയോഗിച്ച് Nginx എങ്ങനെ ഇൻസ്റ്റാൾ ചെയ്യാം
  5. Linux-ൽ Nginx സെർവർ പതിപ്പ് എങ്ങനെ മറയ്ക്കാം

ഇപ്പോഴത്തേക്ക് ഇത്രമാത്രം! ഈ ഗൈഡിൽ, Nginx ആരംഭിക്കുന്നതും പ്രവർത്തനക്ഷമമാക്കുന്നതും പുനരാരംഭിക്കുന്നതും നിർത്തുന്നതും ഉൾപ്പെടെ നിങ്ങൾ അറിഞ്ഞിരിക്കേണ്ട ഏറ്റവും സാധാരണയായി ഉപയോഗിക്കുന്ന Nginx സേവന മാനേജുമെന്റ് കമാൻഡുകളിൽ ചിലത് ഞങ്ങൾ വിശദീകരിച്ചിട്ടുണ്ട്. നിങ്ങൾക്ക് ചോദിക്കാൻ എന്തെങ്കിലും കൂട്ടിച്ചേർക്കലുകളോ ചോദ്യങ്ങളോ ഉണ്ടെങ്കിൽ, ചുവടെയുള്ള ഫീഡ്uബാക്ക് ഫോം ഉപയോഗിക്കുക.