每个Linux用户必须知道的10个最常用的Nginx命令

Nginx(发音为Engine x)是一个免费的,开源的,高性能,可扩展,可靠,功能齐全且流行的HTTP和反向代理服务器,邮件代理服务器和通用TCP/UDP代理服务器。

Nginx以其简单的配置和低资源消耗而闻名,因为它具有高性能,它被用于为Web上的几个高流量站点供电,例如GitHub,SoundCloud,Dropbox,Netflix,WordPress等等。

每个Linux用户必须知道的10个最常用的Nginx命令

在本指南中,我们将介绍一些最常用的Nginx服务管理命令,作为开发人员或系统管理员,您应该随意使用。 我们将显示Systemd和SysVinit的命令。

以下所有Nginx流行命令列表必须以root或sudo用户身份执行,并且应该适用于任何现代Linux发行版,如CentOS,RHEL,Debian,UbuntuFedora

安装Nginx服务器

要安装Nginx Web服务器,请使用默认的分发包管理器,如下所示。

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

要检查Linux系统上安装的Nginx Web服务器的版本,请运行以下命令。

$ nginx -v

nginx version: nginx/1.12.2

上面的命令只显示版本号。 如果要查看版本并配置选项,请使用-V标志,如图所示。

$ nginx -V

显示Nginx,编译器和配置参数

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:
#  * Official Russian Documentation:

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/6330ef901cd9e2635dd756d0ea21afdc.html