当前位置:首页 > 技术文章 > 正文内容

CentOS8 初始环境下安装 Nginx

arlanguage4个月前 (12-27)技术文章30

前言

此教程在刚刚安装成功的 CentOS 8 系统上安装 Nginx。CentOS 8 安装在VMware Fusion 虚拟机上。


CentOS 8 系统初始操作

1、升级所有软件包

执行命令 yum update -y,该命令会升级所有软件包,也会升级软件和系统内核;


2、更新 yum 源

cd /etc/yum.repos.d/
mkdir bak
mv *.repo bak
wget http://mirrors.aliyun.com/repo/Centos-8.repo
yum clean all  # 清除 yum 仓库缓存
yum makecache  # 生成新的 yum 仓库缓存


3、安装基础软件

yum -y install epel-release    # 安装扩展工具包 yum 源
yum install net-tools wget nscd lsof   # 安装工具
yum -y install gcc pcre-devel zlib-devel openssl-devel libxml2-devel libxslt-devel gd-devel GeoIP-devel jemalloc-devel  perl-devel perl-ExtUtils-Embed


安装 Nginx

1、下载 nginx

mkdir -p opt/data/source
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar zxmf nginx-1.18.0.tar.gz


2、安装 nginx

编译 nginx 源码文件需要通过编译配置命令 configure 进行编译配置,编译时可以根据需要带上配置参数;

./configure --help ,查看配置参数项;

--prefix=PATH # 默认值是 /usr/local/,用于指定编译后代码安装目录


2.1、编译 ./configure

./configure \
  --with-threads \
  --with-file-aio \
  --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_geoip_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_auth_request_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-stream=dynamic \
  --with-stream_ssl_module \
  --with-stream_realip_module \
  --with-stream_geoip_module=dynamic \
  --with-stream_ssl_preread_module \
  --with-compat \
  --with-pcre-jit

参数说明:

--with-threads                     enable thread pool support
  --with-file-aio                    enable file AIO support
  --with-http_ssl_module             enable ngx_http_ssl_module
  --with-http_v2_module              enable ngx_http_v2_module
  --with-http_realip_module          enable ngx_http_realip_module
  --with-http_addition_module        enable ngx_http_addition_module
  --with-http_xslt_module=dynamic    enable dynamic ngx_http_xslt_module
  --with-http_image_filter_module=dynamic  enable dynamic ngx_http_image_filter_module
  --with-http_geoip_module=dynamic   enable dynamic ngx_http_geoip_module
  --with-http_sub_module             enable ngx_http_sub_module
  --with-http_dav_module             enable ngx_http_dav_module
  --with-http_flv_module             enable ngx_http_flv_module
  --with-http_mp4_module             enable ngx_http_mp4_module
  --with-http_gunzip_module          enable ngx_http_gunzip_module
  --with-http_gzip_static_module     enable ngx_http_gzip_static_module
  --with-http_auth_request_module    enable ngx_http_auth_request_module
  --with-http_random_index_module    enable ngx_http_random_index_module
  --with-http_secure_link_module     enable ngx_http_secure_link_module
  --with-http_degradation_module     enable ngx_http_degradation_module
  --with-http_slice_module           enable ngx_http_slice_module
  --with-http_stub_status_module     enable ngx_http_stub_status_module
  --with-stream=dynamic              enable dynamic TCP/UDP proxy module
  --with-stream_ssl_module           enable ngx_stream_ssl_module
  --with-stream_realip_module        enable ngx_stream_realip_module
  --with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
  --with-stream_ssl_preread_module   enable ngx_stream_ssl_preread_module
  --with-compat                      dynamic modules compatibility
  --with-pcre-jit                    build PCRE with JIT compilation support

2.2、安装

make && make install

安装之后才会有安装目录,安装前编译后只是指定安装目录 /usr/local/nginx;

默认安装目录是:/usr/local/nginx,可以在编译时用 --prefix=PATH 参数指定安装目录;

可以根据需要在编译时加减参数;


2.3、添加第三方模块

nginx 功能是模块化的;

可以在编译时通过参数 --add-module=PATH(指定静态模块) / --add-dynamic-module=PATH(指定动态模块)指定第三方模块;

编译后在 make install 安装时会把第三方模块安装进来;

扫描二维码推送至手机访问。

版权声明:本文由AR编程网发布,如需转载请注明出处。

本文链接:http://www.arlanguage.com/post/509.html

分享给朋友:

“CentOS8 初始环境下安装 Nginx” 的相关文章

蓝易云 - Nginx 设置禁用 OPTIONS 请求以及允许跨域教程!

在Nginx中禁用OPTIONS请求并允许跨域的教程在现代Web开发中,跨域资源共享(CORS)和处理HTTP请求方法(如OPTIONS)是常见需求。本文将详细介绍如何在Nginx中配置以禁用OPTIONS请求并允许跨域请求。云服务器,高防服务器就选蓝易云,头条搜索:蓝易云云服务器,高防服务器就选蓝...

Nginx Lua编程基础

Lua是一门脚本动态语言,并不太适合做复杂业务逻辑的程序开发,但是,在高并发场景下,Nginx Lua编程是解决性能问题的利器。Nginx Lua编程主要的应用场景如下:API网关:实现数据校验前置、请求过滤、API请求聚合、AB测试、灰度发布、降级、监控等功能,著名的开源网关Kong就是基于Ngi...

Linux系统非root用户下安装Nginx

通常使用Nginx或者Apache作为Web服务器时,默认监听80端口,因此默认会使用root用户去安装,而且,使用yum命令安装时,通常会安装到默认的路径下,默认路径通常是root用户才有执行权限的。如果不需要使用Nginx监听1024以下的端口,且对权限和网络管理比较严格时,能用非root权限解...

我采访了一位 Pornhub 工程师,聊了这些纯纯的话题

成人网站在推动 Web 发展方面所起到的作用无可辩驳。从突破浏览器的视频能力限制,到利用 WebSocket 推送广告(防止被广告拦截器拦截),你必须不断想出各种聪明的办法,让自己处在 Web 技术创新的最前沿。最近,我有幸采访了大型成人网站 Pornhub 的一位 Web 开发工程师,了解了相关的...

Nginx安装、启动、停止、重载、查看

Nginx介绍Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在开源BSD-like 协议下发行。特点是占有内存少,并发能力强。1、安装 Nginx程序yum install nginx -y 或 dnf install nginx -y2、n...

nginx+spring boot 微服务实现负载均衡

环境准备项目 JDK1.8 以上版本准备好 nginx 环境nginx 配置nginx 的配置文件在/usr/local/nginx/conf 目录下,配置文件 nginx.conf配置信息如下:upstream web_app { server 192.168.226.150:8089 ma...