站長(zhǎng)資訊網(wǎng)
        最全最豐富的資訊網(wǎng)站

        每個(gè)Linux用戶必須知道的10個(gè)最常用的Nginx命令

        Nginx(發(fā)音為Engine x)是一個(gè)免費(fèi)的,開源的,高性能,可擴(kuò)展,可靠,功能齊全且流行的HTTP和反向代理服務(wù)器,郵件代理服務(wù)器和通用TCP/UDP代理服務(wù)器。

        Nginx以其簡(jiǎn)單的配置和低資源消耗而聞名,因?yàn)樗哂懈咝阅埽挥糜跒閃eb上的幾個(gè)高流量站點(diǎn)供電,例如GitHub,SoundCloud,Dropbox,Netflix,WordPress等等。

        每個(gè)Linux用戶必須知道的10個(gè)最常用的Nginx命令

        在本指南中,我們將介紹一些最常用的Nginx服務(wù)管理命令,作為開發(fā)人員或系統(tǒng)管理員,您應(yīng)該隨意使用。 我們將顯示Systemd和SysVinit的命令。

        以下所有Nginx流行命令列表必須以root或sudo用戶身份執(zhí)行,并且應(yīng)該適用于任何現(xiàn)代Linux發(fā)行版,如CentOS,RHEL,Debian,Ubuntu和Fedora。

        安裝Nginx服務(wù)器

        要安裝Nginx Web服務(wù)器,請(qǐng)使用默認(rèn)的分發(fā)包管理器,如下所示。

        $ 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版本

        要檢查L(zhǎng)inux系統(tǒng)上安裝的Nginx Web服務(wù)器的版本,請(qǐng)運(yùn)行以下命令。

        $ nginx -v

        nginx version: nginx/1.12.2

        上面的命令只顯示版本號(hào)。 如果要查看版本并配置選項(xiàng),請(qǐng)使用-V標(biāo)志,如圖所示。

        $ nginx -V

        顯示Nginx,編譯器和配置參數(shù)

        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配置語法

        在實(shí)際啟動(dòng)Nginx服務(wù)之前,您可以檢查其配置語法是否正確。 如果您已對(duì)現(xiàn)有配置結(jié)構(gòu)進(jìn)行了更改或添加了新配置,則此功能尤其有用。

        要測(cè)試Nginx配置,請(qǐng)運(yùn)行以下命令。

        $ sudo nginx -t

        nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
        nginx: configuration file /etc/nginx/nginx.conf test is successful

        您可以測(cè)試Nginx配置,轉(zhuǎn)儲(chǔ)它并使用-T標(biāo)志退出,如圖所示。

        $ sudo nginx -T

        顯示Nginx配置設(shè)置

        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 {
                }
            }

        ….

        啟動(dòng)Nginx服務(wù)

        要啟動(dòng)Nginx服務(wù),請(qǐng)運(yùn)行以下命令。 請(qǐng)注意,如果配置語法不正確,此過程可能會(huì)失敗。

        $ sudo systemctl start nginx #systemd
        或者
        $ sudo service nginx start  #sysvinit

        啟用Nginx服務(wù)

        上一個(gè)命令僅在此期間啟動(dòng)服務(wù),要在啟動(dòng)時(shí)啟用它自動(dòng)啟動(dòng),請(qǐng)運(yùn)行以下命令。

        $ sudo systemctl enable nginx #systemd
        或者
        $ sudo service nginx enable  #sysv init

        重啟Nginx服務(wù)

        要重新啟動(dòng)Nginx服務(wù),將停止然后啟動(dòng)該服務(wù)的操作。

        $ sudo systemctl restart nginx #systemd
        或者
        $ sudo service nginx restart  #sysv init

        查看Nginx服務(wù)狀態(tài)

        您可以按如下方式檢查Nginx服務(wù)的狀態(tài)。 此命令顯示有關(guān)服務(wù)的運(yùn)行時(shí)狀態(tài)信息。

        $ sudo systemctl status nginx #systemd
        或者
        $ sudo service nginx status  #sysvinit

        顯示Nginx狀態(tài)信息

        Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
        [root@linuxidc ~]# 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 linuxidc.com systemd[1]: Starting The nginx HTTP and reverse proxy server…
        Mar 05 05:27:15 linuxidc.com nginx[31509]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
        Mar 05 05:27:15 linuxidc.com nginx[31509]: nginx: configuration file /etc/nginx/nginx.conf test is successful
        Mar 05 05:27:15 linuxidc.com systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
        Mar 05 05:27:15 linuxidc.com systemd[1]: Started The nginx HTTP and reverse proxy server.

        重新加載Nginx服務(wù)

        要告訴Nginx重新加載其配置,請(qǐng)使用以下命令。

        $ sudo systemctl reload nginx #systemd
        或者
        $ sudo service nginx reload  #sysvinit

        停止Nginx服務(wù)

        如果您想出于一次性原因而停止Nginx服務(wù),請(qǐng)使用以下命令。

        顯示Nginx命令幫助

        要獲得所有Nginx命令和選項(xiàng)的簡(jiǎn)單參考指南,請(qǐng)使用以下命令。

        $ systemctl -h nginx

        Nginx幫助命令和選項(xiàng)

        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=[USER@]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

        就這樣了! 在本指南中,我們已經(jīng)解釋了一些您應(yīng)該知道的最常用的Nginx服務(wù)管理命令,包括啟動(dòng),啟用,重新啟動(dòng)和停止Nginx。 如果您有任何要求或要求提出的問題,請(qǐng)使用下面的反饋表。

        如何在CentOS Linux 7.5上安裝Nginx  http://m.0106606.com/Linux/2018-05/152399.htm

        在Ubuntu 18.04上安裝帶有Nginx,MariaDB 10和PHP 7的WordPress  http://m.0106606.com/Linux/2019-03/157315.htm

        贊(0)
        分享到: 更多 (0)
        網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)
        主站蜘蛛池模板: 国产精品自在线拍国产电影| 色欲国产麻豆一精品一AV一免费 | 中文成人无码精品久久久不卡 | 国产精品 91 第一页| 久久精品午夜一区二区福利| 国产精品美女免费视频观看 | 精品无码一区二区三区亚洲桃色 | 国产日韩精品无码区免费专区国产| 92国产精品午夜福利| 日韩人妻无码精品一专区| 欧美精品亚洲人成在线观看| 亚洲天堂久久精品| 国产精品久久成人影院| 久久久久久九九99精品| 亚洲午夜精品久久久久久app| 久久99精品国产麻豆婷婷| wwwvr高清亚洲精品二区| 久久精品九九亚洲精品天堂| 99re这里只有精品热久久| 精品9E精品视频在线观看| 久久精品毛片免费观看| 综合人妻久久一区二区精品| 日本精品少妇一区二区三区| 国内精品国语自产拍在线观看| jizz国产精品| 国内精品久久久久久久久电影网| 办公室久久精品| 亚洲国产精品久久66| 久久精品成人国产午夜| 久久精品国产99国产电影网| 国产精品免费网站| 九九精品免视看国产成人| 久久国产精品99久久久久久老狼| 久久国产精品-久久精品| 四虎精品成人免费永久| 99精品影院| 国产亚洲精品免费视频播放| 老司机午夜网站国内精品久久久久久久久 | 97精品国产自在现线免费观看| 亚洲综合国产精品| 国产精品无码永久免费888|