CentOS linux安装nginx

  1. 下载nginx-1.21.3.tar.gz 及 nginx-upstream-fair-master.zip

  2. 上传nginx-upstream-fair-master至/app/server/nginx/modules/解压

c 复制代码
cd /app/server/nginx/modules
unzip nginx-upstream-fair-master.zip
  1. 上传nginx压缩包至**/app/server/nginx/ **(根据自己需求而定)

  2. 切换路劲

c 复制代码
cd /app/server/nginx
  1. 解压
c 复制代码
tar -zxvf nginx-1.21.3.tar.gz
  1. 编辑/app/server/nginx/nginx-1.21.3/auto/lib/openssl/conf文件
c 复制代码
cat /app/server/nginx/nginx-1.21.3/auto/lib/openssl/conf
vim /app/server/nginx/nginx-1.21.3/auto/lib/openssl/conf

将原数据

c 复制代码
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"

修改为:

c 复制代码
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib64/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib64/libcrypto.a"
  1. 修改/app/server/nginx/nginx-1.21.3/src/http/ngx_http_upstream.h文件

新增一个default_port

c 复制代码
struct ngx_http_upstream_srv_conf_s {
ngx_http_upstream_peer_t peer;
void **srv_conf;

ngx_array_t *servers; /* ngx_http_upstream_server_t */

ngx_uint_t flags;
ngx_str_t host;
u_char *file_name;
ngx_uint_t line;
in_port_t port;
in_port_t default_port; /* 新增一个default_port */
ngx_uint_t no_port; /* unsigned no_port:1 */

#if (NGX_HTTP_UPSTREAM_ZONE)
ngx_shm_zone_t *shm_zone;
#endif
};
  1. 切至nginx目录
c 复制代码
cd /app/server/nginx/nginx-1.21.3
  1. 配置
c 复制代码
./configure --prefix=/app/server/nginx/nginx-all --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/openssl3.0.0 --with-openssl-opt="enable-tlsext" --with-http_v2_module --add-module=/app/server/nginx/modules/nginx-upstream-fair-master

配置解释:

c 复制代码
/app/server/nginx/nginx-all 是安装路径,不能安直接安装到解压路径
http_stub_status_module 监控模块
with-http_ssl_module ssl模块
http_gzip_static_module gzip模块
/usr/local/openssl3.0.0 openssl安装路径路径
nginx-upstream-fair-master 负载均衡模块
http_v2_module http2模块
提示./configure: error: the HTTP rewrite module requires the PCRE library.错误时,需要安装pcre-devel(命令:yum -y install pcre-devel)

openssl及其他环境配置安装方法可看:CentOS linux 安装openssl

  1. 编译安装
c 复制代码
make
make install

结束

相关推荐
chian-ocean16 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=18 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
若云止水27 分钟前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
吃汤圆的抹香鲸1 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
sz66cm1 小时前
Linux基础 -- ARM 32 位架构动态注入代码技术文档
linux·arm开发·架构
Mr.pyZhang4 小时前
Android构建系统 - 04 编译产物
android·linux