米饭粑 米饭粑
  • 注册
  • 登录
  • 首页
  • 好物推荐
    • 干货分享
    • 好物推荐
    • 免费资源
    • 非专业测评
  • 技术架构
    • Linux
    • HTTPS
    • Windows Server
  • 网站建设
    • 免费资源
    • 建站程序
    • 云建站
    • WordPress
  • 网络服务
    • CDN
    • DNS
    • HTTPS
  • 教程&更多
    • 更多教程
    • 资讯新闻
    • 琐琐碎碎
    • 关于米饭
    • 打赏米饭
  • 友情链接
  • 阿里云Ping
首页 › 技术架构 › Linux › 在 RHEL8 和 CentOS8 上安装 Nginx

在 RHEL8 和 CentOS8 上安装 Nginx

妙正灰
2年前Linux
960 0 4

介绍

Nginx(发音同 engine x)是一款轻量级的 Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个 BSD-like 协议下发行,可以在 UNIX、GNU/Linux、BSD、Mac OS X、Solaris,以及 Microsoft Windows 等操作系统中运行。

Nginx 作为大型互联网网站的 Web 服务软件有着广泛的支持率,例如阿里系的 Tengine、CloudFlare 的 cloudflare-nginx、又拍云用的 OpenResty 都是基于 Nginx 加入企业的定制化需求,Nginx 是一款接受过大规模访问验证的高性能 Web 服务器软件。同时各大企业也会将自己开发的组件回馈给 Nginx 社区,让 Nginx 有着非常良好的扩展生态。

安装

目前 RHEL8 和 CentOS8 上主要有两种,一个是RHEL系统的 APPStream(应用流)和 Nginx 社区官方的软件源。

RHEL 系统的 APPStream 的稳定性肯定是最高的,也会最贴合系统,APPStream 的,目的是为了保持软件版本跟上主流支持,并让系统同时支持安装多个版本,但是目前不知道 Nginx 是否会有版本的跟进支持

Nginx 社区源则可以体验到最新的 Nginx 版本,但毕竟是社区版本,其中好坏也是仁者见仁智者见智的了。

下面安装将分为 APPStream 和 社区源两个部分

APPStream 安装

由于系统默认包含源,所以我们直接安装即可。

一、安装 Nginx

yum install nginx -y

二、启动软件并设置开机启动

systemctl enable nginx
systemctl start nginx

三、查看命令行检测安装完成。

[root@www.mf8.biz ~]# nginx -V
nginx version: nginx/1.14.1
built by gcc 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC) 
built with OpenSSL 1.1.1 FIPS  11 Sep 2018
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'

四、设置防火墙规则

firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

五、访问IP即可

在 RHEL8 和 CentOS8 上安装 Nginx-米饭粑

配置文件目录

主配置文件:/etc/nginx/nginx.conf

默认文件目录:/usr/share/nginx/html

错误日志:/var/log/nginx/error.log

访问日志:/var/log/nginx/access.log

Nginx 社区源安装

一、安装社区版软件源:

yum install dnf-utils -y

curl -o /etc/yum.repos.d/nginx.repo https://gist.githubusercontent.com/ivmm/23ac854c154e3529a08db68a44ae81c3/raw/c46c159eb5cacd66e69420efa2b12ce6a99fd642/nginx.repo 

二、选择安装稳定版还是主线版

安装稳定版输入:

yum-config-manager --enable nginx-stable

安装主线版(测试版)输入:

yum-config-manager --enable nginx-mainline

三、安装 Nginx

yum --disablerepo=rhel-8-for-x86_64-appstream-rpms install nginx -y

注释:

--disablerepo=rhel-8-for-x86_64-appstream-rpms 这个参数是为了临时屏蔽默认的 APPStream 源,不然会提示找不到 nginx 社区版的包。

四、启动软件并设置开机启动

systemctl enable nginx
systemctl start nginx

五、查看命令行检测安装完成。

[root@www.mf8.biz]# nginx -V
nginx version: nginx/1.16.0
built by gcc 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC) 
built with OpenSSL 1.1.1 FIPS  11 Sep 2018
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

六、设置防火墙规则

firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

七、访问IP即可

在 RHEL8 和 CentOS8 上安装 Nginx-米饭粑

配置文件目录

主配置文件:/etc/nginx/nginx.conf

默认文件目录:/usr/share/nginx/html

错误日志:/var/log/nginx/error.log

访问日志:/var/log/nginx/access.log

APPStream CentOS8 Nginx RHEL8
4
本文系作者 @妙正灰 原创发布在 米饭粑。未经许可,禁止转载。
在阿里云免费领取一年 .design 域名
上一篇
RHEL8 CentOS8 下安装 MySQL 8.0
下一篇
评论 (0)
再想想
标签
Appnode Brotli CDN CentOS CentOS8 Debian DNS ECC ECS Ghost HTTP2 HTTPS IIS IPV6 Linux LiteSpeed MariaDB MySQL Nginx OLS OpenLiteSpeed OpenResty OSS PageSpeed PHP PHP7 QUIC Redis RHEL RHEL8 SSL TokuDB Ubuntu Windows Server 2016 Wordpress 云服务器 升级 域名 对象存储 微软 数据库 百度 笔记本 阿里云 阿里云ACP
文章归档
关注米饭粑微信公众号
4
相关文章
4月4日,全国哀悼,简单CSS代码将网站变成灰色
使用如下姿势预防阿里云 CDN 产生天价账单
RHEL8 CentOS8 快速开启 TCP BBR 实现高效单边加速
Debian10 快速开启 TCP BBR 实现高效单边加速
关于

稻粢穱麦,挐黄梁些,折腾云计算的经验分享和总结。

菜单
首页 教程 好物 关于 链接 打赏
内页链接
米饭粑 米范导航
Copyright © 2011-2021 米饭粑. Designed by nicetheme. 浙ICP备15006212号-1
  • 首页
  • 教程
  • 好物
  • 关于
  • 链接
  • 打赏
热门搜索
  • 402
  • 113
  • 546
  • 548
  • 460
妙正灰
文科屌丝伪IT男一枚.
337 文章
385 评论
378 喜欢
  • 4
  • 0
  • Top