10 सबसे अधिक उपयोग किए जाने वाले नगनेक्स हर लिनक्स उपयोगकर्ता को जानते हैं


Nginx (स्पष्ट इंजन x) एक मुक्त, खुला-स्रोत, उच्च-प्रदर्शन, मापनीय, विश्वसनीय, पूर्ण-विशेषताओं वाला और लोकप्रिय HTTP और रिवर्स प्रॉक्सी सर्वर, एक मेल प्रॉक्सी सर्वर और एक सामान्य टीसीपी/है UDP प्रॉक्सी सर्वर।

Nginx अपने सरल विन्यास के लिए अच्छी तरह से जाना जाता है, और अपने उच्च प्रदर्शन के कारण कम संसाधन खपत के कारण, इसका उपयोग वेब पर कई उच्च-ट्रैफ़िक साइटों को करने के लिए किया जा रहा है, जैसे GitHub , साउंडक्लाउड , ड्रॉपबॉक्स , नेटफ्लिक्स , वर्डप्रेस और कई अन्य।

इस मार्गदर्शिका में, हम कुछ सबसे अधिक इस्तेमाल किए जाने वाले Nginx सेवा प्रबंधन आदेशों की व्याख्या करेंगे, जो एक डेवलपर या सिस्टम प्रशासक के रूप में आपको अपनी उंगलियों पर रखना चाहिए। हम दोनों Systemd और SysVinit के लिए कमांड दिखाएंगे।

इन सभी की निम्न सूची Nginx लोकप्रिय आदेशों को रूट या sudo उपयोगकर्ता के रूप में निष्पादित किया जाना चाहिए और किसी भी आधुनिक लिनक्स वितरण जैसे CentOS पर काम करना चाहिए। , RHEL , डेबियन , Ubuntu और फेडोरा

Nginx सर्वर स्थापित करें

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 संस्करण की जाँच करें

अपने लिनक्स सिस्टम पर स्थापित नग्नेक्स वेब सर्वर के संस्करण की जांच करने के लिए, निम्न कमांड चलाएँ।

$ nginx -v

nginx version: nginx/1.12.2

उपरोक्त कमांड केवल संस्करण संख्या प्रदर्शित करता है। यदि आप संस्करण देखना और कॉन्फ़िगर करना चाहते हैं तो दिखाए गए अनुसार -V ध्वज का उपयोग करें।

$ nginx -V

Nginx, Compiler और कॉन्फ़िगरेशन पैरामीटर दिखाएं

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 कॉन्फ़िगरेशन सेटिंग दिखाएं

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

Nginx स्थिति जानकारी दिखाएं

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 बताने के लिए, निम्न कमांड का उपयोग करें।

$ 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

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
...

आप इन निम्नलिखित नगीनेक्स संबंधित लेखों को पढ़ना पसंद कर सकते हैं।

  1. The Ultimate Guide to Secure, Harden and Improve Performance of Nginx Web Server
  2. Amplify – NGINX Monitoring Made Easy
  3. ngxtop – Monitor Nginx Log Files in Real Time in Linux
  4. How to Install Nginx with Virtual Hosts and SSL Certificate
  5. How to Hide Nginx Server Version in Linux

अभी के लिए इतना ही! इस गाइड में, हमने कुछ सबसे अधिक इस्तेमाल किए जाने वाले Nginx सेवा प्रबंधन आदेशों के बारे में बताया है जिन्हें आपको पता होना चाहिए, जिसमें Nginx शुरू करना, सक्षम करना, पुनरारंभ करना और रोकना शामिल है। यदि आपके पास पूछने के लिए कोई अतिरिक्त या प्रश्न हैं, तो नीचे दिए गए फीडबैक फॉर्म का उपयोग करें।