CentOS7下 yum方式安装Nginx的实现步骤
CentOS7下yum方式安装Nginx的实现步骤
Nginx是一个很强大的高性能Web和反向代理服务器,它具有众多非常优越的特性。诸如低开销,高并发,支持缓存,支持正反向代理,支持负载均衡,支持正则,支持rewrite等等不一而足。所以众多粉丝们也是不计其数。本文基于CentOS7简要描述yum方式的安装部署,供大家参考。
如果是编译安装可以参考:Linux6下安装编译安装Nginx
有关Nginx的常用配置可参考:Nginx概述及日常管理
一、配置nginxyum源
演示环境 [root@centos7-router~]#more/etc/redhat-release CentOSLinuxrelease7.2.1511(Core) [root@centos7-router~]#vim/etc/yum.repos.d/nginx.repo [nginx] name=nginxrepo 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~]#ipaddr|grepinet|grepglobal inet172.24.8.254/24brd172.24.8.255scopeglobaleno16777728 inet192.168.1.175/24brd192.168.1.255scopeglobaldynamiceno33554960
二、安装nginx
[root@centos7-router~]#yuminstallnginx-y [root@centos7-router~]#yuminstallnginx-module-perl.x86_64-y 查看生程的相关文件 [root@centos7-router~]#rpm-qlnginx /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~]#systemctlstartnginx [root@centos7-router~]#systemctlenablenginx###配置自启动 [root@centos7-router~]#ss-nltp|grepnginx LISTEN0128*:80*:*users:(("nginx",pid=65418,fd=6),("nginx",pid=65415,fd=6)) 查看nginx的版本 [root@centos7-router~]#nginx-v nginxversion:nginx/1.12.2 查看或修改配置文件 [root@centos7-router~]#more/etc/nginx/nginx.conf usernginx; worker_processes1; error_log/var/log/nginx/error.logwarn; pid/var/run/nginx.pid; events{ worker_connections1024; } http{ include/etc/nginx/mime.types;###Author:Leshami default_typeapplication/octet-stream;###Blog:http://blog.csdn.net/leshami log_formatmain'$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.logmain; sendfileon; #tcp_nopushon; keepalive_timeout65; #gzipon; 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~]#curlhttp://172.24.8.254Welcometonginx! Welcometonginx!
Ifyouseethispage,thenginxwebserverissuccessfullyinstalledand working.Furtherconfigurationisrequired.
Foronlinedocumentationandsupportpleasereferto
nginx.org.
Commercialsupportisavailableatnginx.com. Thankyouforusingnginx.
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!