首页 > 编程知识 正文

nginx 卸载,yum安装的nginx怎么升级

时间:2023-05-05 04:31:54 阅读:160761 作者:2231

另一方面,在centos等Linux发行版下,使用yum安装nginx

[ root @ www yum.repos.d ] # touch/etc/yum.repos.d/nginx.repo

[ root @ www yum.repos.d ] # vim/etc/yum.repos.d/nginx.repo

将nginx的官方yum源代码添加到此repo文件中

[nginx]

name=nginx repo

base URL=http://nginx.org/packages/centos/releasever/releasever/basearch /

gpgcheck=0

启用=1

然后,可以使用yum install nginx安装nginx。 使用yum安装nginx更简单,相关的SysV脚本也已经写好了,直接使用就可以了。 配置文件日志文件等位置如下:

#配置文件位于/etc/nginx目录中

[root@www ~]# cd /etc/nginx/

[root@www nginx]# ls

conf.dkoi-utf mime.types scgi _ params win-utf

fastcgi _ params koi-winnginx.confu wsgi _ params

#日志文件位于/var/log/nginx目录中

[ root @ www nginx ] # CD/var/log/nginx /

[root@www nginx]# ls

access.log error.log

#pid位于/var/run目录中

[ root @ www nginx ] # cat/var/run/nginx.PID

29361

#nginx默认主页,错误页面html文件

[ root @ www nginx ] # CD/usr/share/nginx /

[root@www nginx]# ls

html

二.如何启动nginx

在Linux上,只需直接运行nginx命令即可启动nginx。 对于通过yum安装的nginx,nginx命令通常位于/usr/sbin目录中。

[root@lifw nginx]# which nginx

/usr/sbin/nginx

[root@lifw nginx]# nginx

三.使用SysV脚本控制nginx

使用官方yum源安装的nginx提供了SysV脚本,使用起来非常简单

[ root @ www init.d ] # servicenginxstop

stopping nginx : [确定]

[ root @ www init.d ] # servicenginxstart

starting nginx : [确定]

[ root @ www init.d ] # servicenginxrestart

stopping nginx : [确定]

starting nginx : [确定]

[ root @ www init.d ] # servicenginxreload

reloading nginx : [确定]

[ root @ www init.d ] # servicenginxstatus

nginx(PID29447 ) is running…

四. Nginx支持以下命令行参数

-h | -?

打印命令行参数的帮助信息。

[root@lifw nginx]# nginx -h

nginx : nginx/1.8.0

Usage: nginx [-? hvtq ] [-ssignal ] [-cfilename ] [-p prefix ] [-gdirectives ]

选项:

-?-h : this help

-v : show version and exit

- v : showversionandconfigureoptionsthenexit

- t :测试配置和扩展

- q :支持非错误消息安全配置


-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /etc/nginx/)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file

-c file

指定配置文件的位置,如果不指定则使用默认的配置文件 /etc/nginx/nginx.conf

#-c 参数用于启动nginx时指定配置文件,如果nginx已经在运行,则启动失败
[root@www nginx]# nginx -c /etc/nginx/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@www nginx]# nginx -s quit
[root@www nginx]# nginx -c /etc/nginx/nginx.conf

-v

打印nginx的版本号。

[root@www nginx]# nginx -v
nginx version: nginx/1.8.0

-V

打印nginx的版本号、编译器版本、配置参数等详细信息。

[root@www nginx]# nginx -V
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --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_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt=’-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic’

-t

检查nginx的配置文件是否有语法错误,通常在修改配置文件后先检查配置文件,然后在重新加载配置文件。

[root@www nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

-T

检查nginx的配置文件是否有语法错误,与 -t 参数相同,但是 -T 同时将配置文件内容通过标准输出(standard output)打印出来。注意仅在 1.9.2 版本以后才支持。

-s signal

给 nginx 主进程发送信号(signal),信号可以是以下几种:

stop 快速关闭 nginx。

quit 平滑关闭 nginx。

reload 重新加载配置文件,使用新配置文件开启一个新的工作进程(worker progress),然后平滑的关闭原来的工作进程。

reopen 重新打开日志文件,如果你发现你的nginx日志文件不再记录日志了,可以使用该指令重新打开日志文件。

#stop指令会快速关闭nginx
[root@www nginx]# nginx -s stop
[root@www nginx]# service nginx status
nginx dead but subsys locked
[root@www nginx]# nginx
[root@www nginx]# service nginx status
nginx (pid 29228) is running…
#quit会平滑关闭nginx,可以看到一段时间内nginx没有被关闭
[root@www nginx]# nginx -s quit
[root@www nginx]# service nginx status
nginx (pid 29228) is running…
[root@www nginx]# service nginx status
nginx (pid 29228) is running…
[root@lifw nginx]# service nginx status
nginx dead but subsys locked
[root@www nginx]# nginx
#重新加载配置文件
[root@www nginx]# nginx -s reload
#重新打开日志文件
[root@www nginx]# nginx -s reopen

-q

在 nginx 进行配置文件测试时只打印错误信息。和 -t 参数配合使用。
[root@www nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@www nginx]# nginx -qt
[root@www nginx]#

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。