[环境部署]Nginx环境部署

以源码编译的方式部署Nginx环境

1、除必要的gcc、make、g++等系统环境建议用apt、yum等工具安装外,其他nginx的依赖库,在这里都会尽量以源码编译的方式安装

Nginx下载

从官网下载源码

官网地址:http://nginx.org/en/download.html

下载stable版本

Nginx编译

解压tar.gz,进入解压后的目录,配置Nginx

./configure --prefix=/home/work/env/nginx

--prefix 可以理解为安装路径,自定义

报错

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

缺少PCRE库

从官网下载最新源码,并编译安装PCRE

官网地址:http://www.pcre.org/

编译安装pcre

参考资料:

https://blog.csdn.net/eddy23513/article/details/81366751

https://www.cnblogs.com/Jordandan/p/10402912.html

重新配置Nginx,带--with-pcre参数

 

报错

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

缺少Zlib库

从官网下载源码,并编译安装Zlib

参考资料:

https://blog.csdn.net/aflyeaglenku/article/details/49124467

重新配置Nginx,带--with-zlib参数

 

看起来配置检查通过了

Configuration summary
  + using PCRE library: /home/work/env/pcre
  + OpenSSL library is not used
  + using zlib library: /home/work/env/zlib

  nginx path prefix: "/home/work/env/nginx"
  nginx binary file: "/home/work/env/nginx/sbin/nginx"
  nginx modules path: "/home/work/env/nginx/modules"
  nginx configuration prefix: "/home/work/env/nginx/conf"
  nginx configuration file: "/home/work/env/nginx/conf/nginx.conf"
  nginx pid file: "/home/work/env/nginx/logs/nginx.pid"
  nginx error log file: "/home/work/env/nginx/logs/error.log"
  nginx http access log file: "/home/work/env/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

下面需要执行make && make install

可以拆开执行,先执行make

报错……实践证明--with-pcre和--with-zlib参数指定的应该是源码路径,而非源码编译安装后的路径,所以重新配置Nginx,指定源码路径

./configure --prefix=/home/work/env/nginx --with-pcre=/home/work/env/pcre2-10.35 --with-zlib=/home/work/env/zlib-1.2.11

重新make

报错……实践证明pcre2是不可以用的,需要下载pcre版本……

In file included from src/core/ngx_core.h:73,
                 from src/core/nginx.c:9:
src/core/ngx_regex.h:15:10: fatal error: pcre.h: No such file or directory
   15 | #include <pcre.h>
      |          ^~~~~~~~
compilation terminated.
make[1]: *** [objs/Makefile:372: objs/src/core/nginx.o] Error 1
make[1]: Leaving directory '/home/work/env/nginx-1.18.0'
make: *** [Makefile:8: build] Error 2

重新下载pcre官网中提供的pcre-xxxxx版本

重新配置编译Nginx

./configure --prefix=/home/work/env/nginx --with-pcre=/home/work/env/pcre-8.44 --with-zlib=/home/work/env/zlib-1.2.11

make

报错……缺少C++编译环境

configure: error: Invalid C++ compiler or C++ compiler flags
make[1]: *** [objs/Makefile:1206: /home/work/env/pcre-8.44/Makefile] Error 1
make[1]: Leaving directory '/home/work/env/nginx-1.18.0'
make: *** [Makefile:8: build] Error 2

使用系统工具例如apt来安装C++环境

参考资料:

https://tieba.baidu.com/p/3359488402?red_tag=0802098441&traceid=

这里用的是ubuntu,执行以下命令即可

sudo apt install g++

重新make

make结束,没有什么异常错误日志

sed -e "s|%%PREFIX%%|/home/work/env/nginx|" \
        -e "s|%%PID_PATH%%|/home/work/env/nginx/logs/nginx.pid|" \
        -e "s|%%CONF_PATH%%|/home/work/env/nginx/conf/nginx.conf|" \
        -e "s|%%ERROR_LOG_PATH%%|/home/work/env/nginx/logs/error.log|" \
        < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory '/home/work/env/nginx-1.18.0'

执行make install,也没什么异常错误日志

make -f objs/Makefile install
make[1]: Entering directory '/home/work/env/nginx-1.18.0'
test -d '/home/work/env/nginx' || mkdir -p '/home/work/env/nginx'
test -d '/home/work/env/nginx/sbin' \
        || mkdir -p '/home/work/env/nginx/sbin'
test ! -f '/home/work/env/nginx/sbin/nginx' \
        || mv '/home/work/env/nginx/sbin/nginx' \
                '/home/work/env/nginx/sbin/nginx.old'
cp objs/nginx '/home/work/env/nginx/sbin/nginx'
test -d '/home/work/env/nginx/conf' \
        || mkdir -p '/home/work/env/nginx/conf'
cp conf/koi-win '/home/work/env/nginx/conf'
cp conf/koi-utf '/home/work/env/nginx/conf'
cp conf/win-utf '/home/work/env/nginx/conf'
test -f '/home/work/env/nginx/conf/mime.types' \
        || cp conf/mime.types '/home/work/env/nginx/conf'
cp conf/mime.types '/home/work/env/nginx/conf/mime.types.default'
test -f '/home/work/env/nginx/conf/fastcgi_params' \
        || cp conf/fastcgi_params '/home/work/env/nginx/conf'
cp conf/fastcgi_params \
        '/home/work/env/nginx/conf/fastcgi_params.default'
test -f '/home/work/env/nginx/conf/fastcgi.conf' \
        || cp conf/fastcgi.conf '/home/work/env/nginx/conf'
cp conf/fastcgi.conf '/home/work/env/nginx/conf/fastcgi.conf.default'
test -f '/home/work/env/nginx/conf/uwsgi_params' \
        || cp conf/uwsgi_params '/home/work/env/nginx/conf'
cp conf/uwsgi_params \
        '/home/work/env/nginx/conf/uwsgi_params.default'
test -f '/home/work/env/nginx/conf/scgi_params' \
        || cp conf/scgi_params '/home/work/env/nginx/conf'
cp conf/scgi_params \
        '/home/work/env/nginx/conf/scgi_params.default'
test -f '/home/work/env/nginx/conf/nginx.conf' \
        || cp conf/nginx.conf '/home/work/env/nginx/conf/nginx.conf'
cp conf/nginx.conf '/home/work/env/nginx/conf/nginx.conf.default'
test -d '/home/work/env/nginx/logs' \
        || mkdir -p '/home/work/env/nginx/logs'
test -d '/home/work/env/nginx/logs' \
        || mkdir -p '/home/work/env/nginx/logs'
test -d '/home/work/env/nginx/html' \
        || cp -R html '/home/work/env/nginx'
test -d '/home/work/env/nginx/logs' \
        || mkdir -p '/home/work/env/nginx/logs'
make[1]: Leaving directory '/home/work/env/nginx-1.18.0'

在--prefix指定的路径下顺利部署nginx文件结构

conf  配置文件目录
html  默认的html文件目录
logs  日志目录
sbin  二进制文件目录

尝试启动服务

./sbin/nginx 需要root权限启动

浏览器访问127.0.0.1查看nginx是否启动成功

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值