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 {
        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@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/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM