您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關CentOS7中如何通過yum方式安裝Nginx的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
CentOS7下 yum方式安裝Nginx的實現步驟
Nginx 是一個很強大的高性能Web和反向代理服務器,它具有眾多非常優越的特性。諸如低開銷,高并發,支持緩存,支持正反向代理,支持負載均衡,支持正則,支持rewrite等等不一而足。所以眾多粉絲們也是不計其數。本文基于CentOS 7簡要描述yum方式的安裝部署,供大家參考。
如果是編譯安裝可以參考:Linux 6下安裝編譯安裝Nginx
有關Nginx的常用配置可參考:Nginx 概述及日常管理
一、配置nginx yum源
演示環境 [root@centos7-router ~]# more /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@centos7-router ~]# vim /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,OSRELEASE替換為6或者7,即當前的Linux為6還是7版本 查看本機ip [root@centos7-router ~]# ip addr|grep inet|grep global inet 172.24.8.254/24 brd 172.24.8.255 scope global eno16777728 inet 192.168.1.175/24 brd 192.168.1.255 scope global dynamic eno33554960
二、安裝nginx
[root@centos7-router ~]# yum install nginx -y [root@centos7-router ~]# yum install nginx-module-perl.x86_64 -y 查看生程的相關文件 [root@centos7-router ~]# rpm -ql nginx /etc/logrotate.d/nginx /etc/nginx /etc/nginx/conf.d /etc/nginx/conf.d/default.conf /etc/nginx/fastcgi_params /etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/mime.types /etc/nginx/modules /etc/nginx/nginx.conf /etc/nginx/scgi_params /etc/nginx/uwsgi_params /etc/nginx/win-utf /etc/sysconfig/nginx /etc/sysconfig/nginx-debug /usr/lib/systemd/system/nginx-debug.service /usr/lib/systemd/system/nginx.service /usr/lib64/nginx /usr/lib64/nginx/modules /usr/libexec/initscripts/legacy-actions/nginx /usr/libexec/initscripts/legacy-actions/nginx/check-reload /usr/libexec/initscripts/legacy-actions/nginx/upgrade /usr/sbin/nginx /usr/sbin/nginx-debug /usr/share/doc/nginx-1.12.2 /usr/share/doc/nginx-1.12.2/COPYRIGHT /usr/share/man/man8/nginx.8.gz /usr/share/nginx /usr/share/nginx/html /usr/share/nginx/html/50x.html /usr/share/nginx/html/index.html /var/cache/nginx /var/log/nginx
三、驗證nginx
啟動nginx root@centos7-router ~]# systemctl start nginx [root@centos7-router ~]# systemctl enable nginx ###配置自啟動 [root@centos7-router ~]# ss -nltp|grep nginx LISTEN 0 128 *:80 *:* users:(("nginx",pid=65418,fd=6),("nginx",pid=65415,fd=6)) 查看nginx的版本 [root@centos7-router ~]# nginx -v nginx version: nginx/1.12.2 查看或修改配置文件 [root@centos7-router ~]# more /etc/nginx/nginx.conf user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; ### Author : Leshami default_type application/octet-stream; ### Blog : http://blog.csdn.net/leshami log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; } [root@centos7-router ~]# firewall-cmd --add-service=http --permanent [root@centos7-router ~]# firewall-cmd --reload 從其他機器驗證nginx [root@centos7-web ~]# curl http://172.24.8.254 <!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> <h2>Welcome to nginx!</h2> <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/" rel="external nofollow" >nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/" rel="external nofollow" >nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
感謝各位的閱讀!關于“CentOS7中如何通過yum方式安裝Nginx”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。