nginx安装(CentOS)

在此只说明以yum的方式安装

一,安装前的准备工作

1,四项确认,二项安装,一项初始化





二,下载与安装

1,官方网址:http://nginx.org/en/download.html(线上环境建议安装稳定版)

2,点击查看仓库配置



3,CentOS系统平台yum仓库配置



要设置CentOS的yum存储库,需要创建一个名称为/etc/yum.repos.d/nginx.repo的文件,其中包含以下内容:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

根据所使用的分配,将“OS”替换为“rhel”或“centos”,对于5.x6.x7.x,请将“OSRELEASE”替换为“5”,“6”或“7” 版本。

有关于如何查看系统版本 

[root@localhost nginx-1.10.3]# lsb_release -a
bash:lsb_release: command not found
[root@localhost nginx-1.10.3]# yum install lsb –y
[root@localhost nginx-1.10.3]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.3.1611 (Core)
Release:        7.3.1611
Codename:       Core
[root@localhost nginx-1.10.3]#

4,查看nginx版本信息等


5.进行安装


三,查看安装信息,以及配置(配置参数详见上篇文章)



四,服务的操作

1. 启动 Nginx 测试

root@localhost:~$ sudo /etc/init.d/nginx
Usage: /etc/init.d/nginx {start|stop|status|restart|reload|force-reload|upgrade|configtest|check-reload}
root@localhost:~$ sudo /etc/init.d/nginx start
[ ok ] Starting nginx (via systemctl): nginx.service.
root@localhost:~$
2. 查询nginx进程

2. 查询nginx进程

root@localhost:~$ ps -ef | grep nginx
root       9933      1  0 20:36 ?        00:00:00 nginx: master process /usr/sbi                        n/nginx -c /etc/nginx/nginx.conf
nginx      9938   9933  0 20:36 ?        00:00:00 nginx: worker process
yiibai     9978   8461  0 20:40 pts/0    00:00:00 grep --color=auto nginx
root@localhost:~$

上面输出结果中,master就代表该进程是nginx的主进程,它的进程ID是:9933

3. 停止nginx

要停止Nginx,可以使用以下命令

kill -QUIT 主进程号

本例中就是 : kill -QUIT 9933
当然还有通用的停止进程的命令,那就是暴力停止了。
kill -9 进程号
kill一个进程,在查询一下进程是否还存在,一个个的kill,全部kill完就可以了。

4. 测试nginx服务

在终端上使用:curl localhost 

root@localhost:~$ curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
root@localhost:~$



猜你喜欢

转载自blog.csdn.net/echizao1839/article/details/80870288