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>
<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>
原文链接:https://www.f2er.com/centos/375471.html