CentOS 7下 yum方式安装Nginx

简介: Nginx 是一个很强大的高性能Web和反向代理服务器,它具有众多非常优越的特性。诸如低开销,高并发,支持缓存,支持正反向代理,支持负载均衡,支持正则,支持rewrite等等不一而足。

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,即当前的Linux6还是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>

DBA牛鹏社(SQL/NOSQL/LINUX)

这里写图片描述

目录
相关文章
|
22小时前
|
Linux Apache
Centos7 安装Apache
安装Apache的步骤
15 6
|
1天前
|
网络协议 Linux Docker
在centos7下通过docker 安装onlyoffice
在centos7下通过docker 安装onlyoffice
|
1天前
|
NoSQL Linux Redis
本地虚拟机centos7通过docker安装主从redis3.2
本地虚拟机centos7通过docker安装主从redis3.2
|
1天前
|
关系型数据库 MySQL Linux
本地虚拟机centos7通过docker安装主从mysql5.7.21
本地虚拟机centos7通过docker安装主从mysql5.7.21
|
1天前
|
Linux 数据安全/隐私保护 Docker
在centos7虚拟机上安装docker oracle11g
在centos7虚拟机上安装docker oracle11g
|
2天前
|
应用服务中间件 nginx Docker
docker安装nginx
`docker search`找镜像,`pull`下载,后台 `-d` 运行容器,命名 `--name`,映射端口 `-p`。本机测试,确保服务器安全组开放端口,公网通过`http://ip:port`访问。用`docker stop id`停止容器。[查看详情](https://blog.csdn.net/javayoungcoolboy/article/details/134976510)
|
2天前
|
安全 Linux 开发者
CentOS 7安装全解析:适合初学者的指导
CentOS 7安装全解析:适合初学者的指导
|
2天前
|
应用服务中间件 网络安全 nginx
nginx(1.13.7)首次安装出现:【make: *** 没有规则可以创建“default”需要的目标“build” 问题】解决措施
nginx(1.13.7)首次安装出现:【make: *** 没有规则可以创建“default”需要的目标“build” 问题】解决措施
|
3天前
|
关系型数据库 MySQL Linux
在Centos7中:通过Docker安装MySQL5.7(保姆级)
在Centos7中:通过Docker安装MySQL5.7(保姆级)
|
3天前
|
存储 安全 Linux
Centos停止更新?这篇博客教会你安装平替Centos的操作系统安装Anolis
Centos停止更新?这篇博客教会你安装平替Centos的操作系统安装Anolis