centos7 rpm安装nginx

一、下载nginx rpm包

地址为:

http://nginx.org/packages/centos/7/x86_64/RPMS/

下载nginx-1.18.0-1.el7.ngx.x86_64包

[root@iZ2ze6bgt1xmvd4jc0v7nmZ src]# wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm

二、查询是否已经安装了nginx

[root@iZ2ze6bgt1xmvd4jc0v7nmZ src]# rpm -qa|grep nginx

如果有安装了 ,执行 rpm  -e 进行卸载

三、执行rpm命令安装

rpm 安装方式nginx 默认安装位置在 /etc/nginx/ 目录下

[root@iZ2ze6bgt1xmvd4jc0v7nmZ src]# rpm -ivh nginx-1.18.0-1.el7.ngx.x86_64.rpm 
warning: nginx-1.18.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:nginx-1:1.18.0-1.el7.ngx         ################################# [100%]
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* http://nginx.org/en/support.html

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

四、启动nginx

[root@iZ2ze6bgt1xmvd4jc0v7nmZ local]# systemctl start nginx 

五、查询nginx

[root@iZ2ze6bgt1xmvd4jc0v7nmZ local]# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-04-06 11:36:21 CST; 1min 38s ago
     Docs: http://nginx.org/en/docs/
  Process: 2677 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 2678 (nginx)
    Tasks: 2
   Memory: 1.5M
   CGroup: /system.slice/nginx.service
           ├─2678 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           └─2679 nginx: worker process

Apr 06 11:36:21 iZ2ze6bgt1xmvd4jc0v7nmZ systemd[1]: Starting nginx - high performance web server...
Apr 06 11:36:21 iZ2ze6bgt1xmvd4jc0v7nmZ systemd[1]: Started nginx - high performance web server.
[root@iZ2ze6bgt1xmvd4jc0v7nmZ local]# 

六、访问web

[root@iZ2ze6bgt1xmvd4jc0v7noZ ~]# curl 172.27.6.3
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
         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@iZ2ze6bgt1xmvd4jc0v7noZ ~]# 

七、设置开机自启动

查询nginx是否开机自启动

[root@iZ2ze6bgt1xmvd4jc0v7nmZ local]# systemctl list-unit-files |grep nginx
nginx-debug.service                           disabled
nginx.service                                 disabled
[root@iZ2ze6bgt1xmvd4jc0v7nmZ local]# 

设置允许开机自启动

[root@iZ2ze6bgt1xmvd4jc0v7nmZ local]# systemctl enable nginx 
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service

再次查询

[root@iZ2ze6bgt1xmvd4jc0v7nmZ local]# systemctl list-unit-files|grep nginx
nginx-debug.service                           disabled
nginx.service                                 enabled 
[root@iZ2ze6bgt1xmvd4jc0v7nmZ local]# 

rpm 安装方式nginx 默认安装位置在 /etc/nginx/ 目录下

八、卸载

[root@iZ2ze6bgt1xmvd4jc0v7nmZ nginx]# rpm -qa|grep nginx
nginx-1.18.0-1.el7.ngx.x86_64

停止nginx服务

[root@iZ2ze6bgt1xmvd4jc0v7nmZ nginx]# systemctl stop nginx

卸载

[root@iZ2ze6bgt1xmvd4jc0v7nmZ nginx]# rpm -e nginx

删除目录

[root@iZ2ze6bgt1xmvd4jc0v7nmZ nginx]# rm -rf /etc/nginx/
原文地址:https://www.cnblogs.com/sky-cheng/p/14621145.html