源码安装nginx 1.23.1

2023-05-16

先看看仓库们

yum list nginx*

已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile

  • base: mirrors.aliyun.com
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
    已安装的软件包
    nginx-filesystem.noarch 1:1.20.1-9.el7 @epel
    可安装的软件包
    nginx.x86_64 1:1.22.0-1.el7.ngx nginx
    nginx-all-modules.noarch 1:1.20.1-9.el7 epel >
    nginx-debug.x86_64 1:1.8.0-1.el7.ngx nginx
    nginx-debuginfo.x86_64 1:1.22.0-1.el7.ngx nginx
    nginx-mod-devel.x86_64 1:1.20.1-9.el7 epel
    nginx-mod-http-image-filter.x86_64 1:1.20.1-9.el7 epel
    nginx-mod-http-perl.x86_64 1:1.20.1-9.el7 epel
    nginx-mod-http-xslt-filter.x86_64 1:1.20.1-9.el7 epel
    nginx-mod-mail.x86_64 1:1.20.1-9.el7 epel
    nginx-mod-stream.x86_64 1:1.20.1-9.el7 epel
    nginx-module-geoip.x86_64 1:1.22.0-1.el7.ngx nginx
    nginx-module-geoip-debuginfo.x86_64 1:1.22.0-1.el7.ngx nginx
    nginx-module-image-filter.x86_64 1:1.22.0-1.el7.ngx nginx
    nginx-module-image-filter-debuginfo.x86_64 1:1.22.0-1.el7.ngx nginx
    nginx-module-njs.x86_64 1:1.22.0+0.7.6-1.el7.ngx nginx
    nginx-module-njs-debuginfo.x86_64 1:1.22.0+0.7.6-1.el7.ngx nginx
    nginx-module-perl.x86_64 1:1.22.0-1.el7.ngx nginx
    nginx-module-perl-debuginfo.x86_64 1:1.22.0-1.el7.ngx nginx
    nginx-module-xslt.x86_64 1:1.22.0-1.el7.ngx nginx
    nginx-module-xslt-debuginfo.x86_64 1:1.22.0-1.el7.ngx nginx
    nginx-nr-agent.noarch 2.0.0-12.el7.ngx nginx

官方nginx 仓库主程序 到 1.22 , 没有全模块,阿里epel 仓库里 全模块 nginx-all-modules 只到 1.20。(我一开始不懂,装epel的 nginx-all-modules 1.20 时候总报错)。后来了解了一下最重要的会话保持模块sticky ,估计全模块也不可能包含它。只有弃用现成包了。

卸载前了解一下现成包怎么编译和做配置文件的

 nginx -V

nginx version: nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
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 -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC’ --with-ld-opt=‘-Wl,-z,relro -Wl,-z,now -pie’

confiture 换好行看看

–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 -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong
–param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC’
–with-ld-opt=‘-Wl,-z,relro -Wl,-z,now -pie’

/etc/nginx/nginx.conf
其中最有参考价值的是

include conf.d/*.conf

然后 新建 conf.d 文件夹,里面有default.conf

做个自己。configure, make, make install

http://nginx.org/en/download.html

结合前面的 confugre参数+官方参数说明文档+自己的需求(sticky)

./configure --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=dynamic                                                          \
--with-mail_ssl_module                                                       \
--with-stream=dynamic                                                        \
--with-stream_realip_module                                                  \
--with-stream_ssl_module                                                     \
--with-stream_ssl_preread_module                                             \
--with-zlib=/usr/local/src/zlib-1.2.12                                       \
--with-openssl=/usr/local                                                    \
--with-debug                                                                 \
--add-module=/mnt/install/nginx/nginx-goodies-nginx-sticky-module-ng-08a395c66e42

说明:

  1. 文件都放默认的/usr/local/nginx,主程序做个链接到/usr/local/sbin,文件夹做个链接到熟悉的/etc/nginx。其他什么进程id,临时文件都不理了,要的以后修改nginx.conf
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
ln -s /usr/local/nginx/           /etc/nginx
  1. 还有以下几个参数我感觉用不到就没添加了,要添加的话,实测还要装其他包(前面yum list 可以看出端儿)。用户名和组也不理了

–user=nginx
–group=nginx
–with-http_xslt_module=dynamic
–with-http_image_filter_module=dynamic
–with-http_geoip_module=dynamic
–with-http_perl_module=dynamic
–with-perl_modules_path
–with-perl
–with-stream_geoip_module=dynamic
–add-dynamic-module

  1. 由于等保要求,我的zlib, openssl 都是源码安装最新版的,所以以上配置增加了 --with-zlib, --with-openssl ,但是都会报错,需要做以下修改。(你们没源码最新版要求,可以去除这两个参数)
  • openssl
vim auto/lib/openssl/conf

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”

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”

  • zlib
vim auto/lib/zlib/conf

CORE_LIBS=“$CORE_LIBS $ZLIB/adler32.o”
CORE_LIBS=“$CORE_LIBS $ZLIB/crc32.o”
CORE_LIBS=“$CORE_LIBS $ZLIB/deflate.o”
CORE_LIBS=“$CORE_LIBS $ZLIB/trees.o”
CORE_LIBS=“$CORE_LIBS $ZLIB/zutil.o”
CORE_LIBS=“$CORE_LIBS $ZLIB/compress.o”

他要的是源码目录,不是安装后库的目录

  1. sticky
    https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/downloads/
  • make 的时候报错

/usr/local/src/nginx-1.23.1/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c: 在函数‘ngx_http_init_sticky_peer’中:
/usr/local/src/nginx-1.23.1/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c:207:54: 错误:‘ngx_http_headers_in_t’没有名为‘cookies’的成员
if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &iphp->sticky_conf->cookie_name, &route) != NGX_DECLINED) {
^
/usr/local/src/nginx-1.23.1/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c:207:2: 错误:传递‘ngx_http_parse_multi_header_lines’的第 2 个参数时在不兼容的指针类型间转换 [-Werror]
if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &iphp->sticky_conf->cookie_name, &route) != NGX_DECLINED) {
^
In file included from /usr/local/src/nginx-1.23.1/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c:9:0:
src/http/ngx_http.h:106:18: 附注:需要类型‘struct ngx_table_elt_t *’,但实参的类型为‘struct ngx_str_t *’
ngx_table_elt_t *ngx_http_parse_multi_header_lines(ngx_http_request_t *r,
^
/usr/local/src/nginx-1.23.1/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c:207:2: 错误:提供给函数‘ngx_http_parse_multi_header_lines’的实参太少
if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &iphp->sticky_conf->cookie_name, &route) != NGX_DECLINED) {
^
In file included from /usr/local/src/nginx-1.23.1/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c:9:0:
src/http/ngx_http.h:106:18: 附注:在此声明
ngx_table_elt_t *ngx_http_parse_multi_header_lines(ngx_http_request_t *r,
^
cc1: all warnings being treated as errors
make[1]: *** [objs/addon/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.o] 错误 1
make[1]: 离开目录“/usr/local/src/nginx-1.23.1”

  • 解决方案
    https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/pull-requests/
vim ngx_http_sticky_module.c

if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &iphp->sticky_conf->cookie_name, &route) != NGX_DECLINED) {
if (ngx_http_parse_multi_header_lines(r, r->headers_in.cookie, &iphp->sticky_conf->cookie_name, &route) != NULL) {

真正的编译安装

make; make install
vim /usr/local/nginx/conf/nginx.conf

在 [http] 里,注释掉 整个[server] 段,增加

include conf.d/*.conf;

mkdir /usr/local/nginx/conf/conf.d
vim /usr/local/nginx/conf/conf.d/upstreams.conf

upstream aaa {
sticky;
server localhost:8080;
}
upstream bbb{
#server 111.222.111.222;
#server 222.111.222.111;
sticky;
server localhost:8080;
}

vim /usr/local/nginx/conf/conf.d/servers.conf

#server {
# listen 80;
# #server_name localhost;
#
# #access_log /var/log/nginx/host.access.log main;
#
# location /zhbm {
# proxy_pass http://zhbm;
# }
#
#
#}
server {
listen 443 ssl;
# ssl_protocols TLSv1.3;
ssl_certificate conf.d/myca.crt;
ssl_certificate_key conf.d/myca.key;
location /aaa{
proxy_pass http://aaa;
}
location /bbb {
proxy_pass http://bbb;
}
}

上面还开了自签ssl https,我在其他文章里也写到生成自签ssl证书

openssl genrsa -out myca.key;
openssl req -new -x509 -days 3650 -key myca.key -out myca.crt

等保要求我还要开着selinux,要正常运行,还要执行

setsebool -P httpd_can_network_connect 1;
setsebool -P httpd_can_network_relay   1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

源码安装nginx 1.23.1 的相关文章

随机推荐

  • STM32F103ZE驱动PMW3901光流模块

    本文将会简单的介绍如何使用STM32F103ZE驱动PMW3901光流模块 xff0c 使用标准库 所用材料如下 一块 STM32F103最小系统板以及一个 PMW3901光流模块 通过查阅PMW3901的数据手册可以得知 xff0c 该芯
  • 计算两圆相交面积

    转自 xff1a 模板 求两圆相交面积 xff08 模板 xff09 两圆相交分如下集中情况 xff1a 相离 相切 相交 包含 设两圆圆心分别是O1和O2 xff0c 半径分别是r1和r2 xff0c 设d为两圆心距离 又因为两圆有大有小
  • 深蓝学院-移动机器人运动规划重点笔记

    移动机器人运动规划笔记 xff0c 转载自https blog csdn net wqwqqwqw1231 article details 107310965 感谢原作者的总结 xff01
  • TFmini Plus在Arduino上的开发例程(二)

    本例程以Arduino Uno板为例 xff0c 通过Arduino实现TFmini Plus相关指令的写入 xff0c 上行数据的读取 判断和测量数据的获取打印 xff0c 主要帮助客户快速熟悉我公司雷达 xff0c 减少产品的研发周期
  • Linux命令发送Http GET/POST请求

    Linux命令发送Http GET POST请求 Get请求 1 使用curl命令 xff1a curl span class token string 34 http www baidu com 34 span 如果这里的URL指向的是一
  • VSCode 常用设置项

    代码编辑工具VSCode 常用设置项 span class token punctuation span span class token comment VScode主题配置 span span class token string 34
  • 机器人运动控制-上位机通讯

    机器人 xff0c 无论是工业机器人还是服务机器人等多种类机器人 xff0c 都有自己的控制器 在他们的控制面板上 xff0c 我们可以通过简单的操作和程序指令 xff0c 让机器人自行运动 为了让机器人更加智能 xff0c 我们需要在机器
  • Imu误差模型、零偏、零偏稳定性

    原文链接 零偏 xff0c 零偏稳定性和零偏重复性 xff0c IMU误差模型 什么是零偏 xff08 Bias xff09 在陀螺静止时 xff0c 陀螺仪仍会 xff0c 以规定时间内测得的输出量平均值相应的等效输入角速率表示 xff0
  • 海思3516a实现OSD叠加水印

    文章目录 前言一 三个文件的编译二 海思SDK使用步骤1 创建叠加字符2 添加叠加区域到视频通道 总结 前言 两天的努力终于实现了 xff0c 激动 xff01 在网上查阅了各种资料 xff0c 只是有零散的信息 xff0c 海思3516a
  • 结合下图,说明UART的工作原理

    结合下图 xff0c 说明UART的工作原理 UART提供三个独立的异步串行I O口 xff0c 他们可以运行于中断模式或者DMA模式 xff0c 也就是说UART可以产生中断请求或者DMA请求 xff0c 以便在CPU和UART之间传输数
  • 深入理解计算机系统 -- 大端与小端字节序

    一 大端字节序 vs 小端字节序 字节序指一个多字节对象在内存中存储的方式 xff0c 小端字节序机器在存储多字节对象时采用低地址存低有效字节的策略 xff0c 大端则恰恰相反 字节序由CPU架构决定 xff0c 与操作系统无直接关系 像常
  • TCP连接建立

    TCP 一种面向来连接的 可靠的 基于字节流的传输层通信协议 面向连接 xff1a 数据在发送之前必须在两端建立连接 xff0c 方法就是我们熟知的三次握手连接 可靠传输 xff1a 通过多种机制来保证数据的正确传输 xff0c 比如序列号
  • UDP接收端收不到广播的消息问题排查

    网络调试助手可以互相发送 xff0c 而你的UDP广播代码却不行 你是广播 是不会被路由器转发的 但是在同一个交换机下 是可以收到广播的 还有就是 电脑的虚拟网卡会拦截广播操作 xff0c 因为你没有指定一个地址 xff0c 所以代码正确的
  • STM32带FIFO的DMA传输应用示例

    STM32系列芯片都内置DMA外设 xff0c 其中很多系列的DMA配备了FIFO 这里以STM32F429芯片及开发板为例 xff0c 演示一下带FIFO的DMA传输实现过程 大致情况是这样的 xff0c 我用TIMER1通道1的比较事件
  • 两种方式判断内存的大小端存储方式

    1 目的 xff1a 判断ubuntu操作系统的内存属于大端还是小端存储 2 源代码 两种方法判断大小端 xff08 处理器取值时的字节序 xff09 xff1a 1 字符指针 2 联合体 法1 if 1 include lt stdio
  • 字符串:求str1在str2中首次出现的位置。

    span class token macro property span class token directive keyword include span span class token string lt stdio h gt sp
  • 基于ROS利用客户端和服务端实现C++节点和python节点间传送图像

    基于ROS利用客户端和服务端实现C 43 43 节点和python节点间传送图像 配置ROS下和python3通信以及配置python3可用的cv bridge 环境安装和使用 参考 xff1a https blog csdn net qq
  • iMaxB6充电介绍

    iMaxB6是一款多用途充电器 xff0c 能够为Li ion Li Poly Li Fe Ni Cd Ni MH和Pb类型电池充电 xff0c 支持6串以内的平衡充电 简要步骤 xff1a 1 连接正负电源 xff1b 2 连接平衡线 x
  • 基于stm32串口环形缓冲队列处理机制

    原文链接 xff1a 基于stm32串口环形缓冲队列处理机制 入门级 xff08 单字节 xff09 串口环形缓冲区实验 1 1 实验简介 最简单的串口数据处理机制是数据接收并原样回发的机制是 xff1a 成功接收到一个数 xff0c 触发
  • 源码安装nginx 1.23.1

    先看看仓库们 yum list nginx 已加载插件 xff1a fastestmirror langpacks Loading mirror speeds from cached hostfile base mirrors aliyun