前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ningx - 源码安装Nginx已经编译时error解决办法

Ningx - 源码安装Nginx已经编译时error解决办法

原创
作者头像
stark张宇
发布2023-02-08 13:34:49
9380
发布2023-02-08 13:34:49
举报
文章被收录于专栏:stark张宇stark张宇

概述

nginx是一款非常好用的反向代理服务器,web服务器,很多人都在使用nginx作为网络服务器,要知其然还要知所以然,所以源码安装是一切实践的基础,让我们动手搞起来。

官网下载合适的版本,建议选择稳定版本,我选择的基础镜像是Centos7,nginx版本是nginx-1.20.2。

代码语言:txt
复制
# 官网地址:https://nginx.org
wget https://nginx.org/download/nginx-1.20.2.tar.gz

1.下载安装包、解压

代码语言:txt
复制
wget https://nginx.org/download/nginx-1.20.2.tar.gz \
tar zxf nginx-1.20.2.tar.gz && \
cd nginx-1.20.2

目录和目录说明:

代码语言:txt
复制
|-- CHANGES
|-- CHANGES.ru
|-- LICENSE
|-- README
|-- auto
|-- conf
|-- configure
|-- contrib
|-- html
|-- man
`-- src
  • auto目录:用于编译时的文件,以及相关lib库,编译时对对操作系统的判断等,都是为了辅助./configure命令执行的辅助文件。
  • CHANGES文件:就是当前版本的说明信息,比如新增的功能,修复的bug,变更的功能等
  • CHANGES.ru文件:作者是俄罗斯人,生成了一份俄罗斯语言的CHANGE文件
  • conf目录:是nginx编译安装后的默认配置文件或者示列文件,安装时会拷贝到安装的文件夹里面。
  • configure文件:编译安装前的预备执行文件。
  • html目录:编译安装的默认的2个标准web页面,安装后会自动拷贝到nginx的安装目录下的html下。
  • man目录:nginx命令的帮助文档,linux上可以使用man命令查看帮助
  • src:nginx的源码文件

2.源码安装

开始编译,执行./configure ,不清楚的可以执行./configure --help #查看./configure 支持哪些参数。

代码语言:txt
复制
# 安装目录
--prefix=PATH

# 配置文件
--conf-path=PATH

# 设置用户和工作组
--user=USER
--group=GROUP

--with-http_ssl_module 表示未开启的模块,如果想启动在编译安装时添加。

--without-http_uwsgi_module 默认是已经安装开启的模块,如果想默认关闭添加参数

备注:日常生产环境使用nginx,编译模块按照nginx官方yum安装的模块,基本能满足95%以上的生产需求。yum安装模块如下,可自行参考:

代码语言:txt
复制
./configure --prefix=/usr/local/nginx
--with-compat \
--with-debug \
--with-file-aio \
--with-google_perftools_module \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_degradation_module  \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module  \
--with-http_image_filter_module=dynamic \
--with-http_mp4_module \
--with-http_perl_module=dynamic \
--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-http_xslt_module=dynamic  \
--with-mail=dynamic \ 
--with-mail_ssl_module --with-pcre  \
--with-pcre-jit --with-stream=dynamic \
--with-stream_ssl_module  \
--with-stream_ssl_preread_module \
--with-threads --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'

备注:nginx使用yum源安装,可能导致业务上很多需要的功能模块没有开启,还是按需自己编译比较合适。

以上扩展需要的安装源,先执行依赖,再执行./configure,然后make install

代码语言:txt
复制
yum -y update && yum install -y gcc wget tree pcre-devel \
zlib-devel openssl openssl-devel \
libxml2 libxml2-dev libxslt-devel gd-devel \
ncurses-devel perl perl-ExtUtils-Embed \
gperftools

安装完成后,添加软链接,加入到环境变量中

代码语言:txt
复制
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx 

启动nginx

代码语言:txt
复制
nginx  -c /usr/local/nginx/conf/nginx.conf

至此

至此,nginx安装完成了,nginx的安装还是非常简单的,主要的难点在于需要先安装编译所需要的依赖。

过程中的报错信息已经解决办法:

./configure: error: the HTTP XSLT module requires the libxml2/libxslt

代码语言:txt
复制
yum -y install libxml2 libxml2-dev
yum -y install libxslt-devel

./configure: error: perl module ExtUtils::Embed is required

代码语言:txt
复制
yum -y install perl-devel perl-ExtUtils-Embed

./configure: error: the Google perftools module requires the Google perftools

代码语言:txt
复制
yum install –y gperftools

./configure: error: the HTTP image filter module requires the GD library.

代码语言:txt
复制
yum -y install gd-devel

perl 5.6.1 or higher is required 出现这个的原因是因为 perl 版本太低了,需要进行升级。

./configure: error: the HTTP gzip module requires the zlib library.

代码语言:txt
复制
yum install -y zlib-devel

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 概述
    • 1.下载安装包、解压
      • 2.源码安装
      • 至此
        • ./configure: error: the HTTP XSLT module requires the libxml2/libxslt
          • ./configure: error: perl module ExtUtils::Embed is required
            • ./configure: error: the Google perftools module requires the Google perftools
              • ./configure: error: the HTTP image filter module requires the GD library.
                • perl 5.6.1 or higher is required 出现这个的原因是因为 perl 版本太低了,需要进行升级。
                  • ./configure: error: the HTTP gzip module requires the zlib library.
                  领券
                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档