随笔-记安装nginx遇到的问题

源码

仓库:https://github.com/nginx/nginx.git

分支:branches/stable-1.20

安装配置

使用configure 命令进行配置。它定义了系统的各个方面配置,包括 Nginx 允许用于连接处理的方法,并且最终创建一个 Makefile 文件。

cd nginx

帮助:./auto/configure --help

配置:./auto/configure 采用默认选项进行配置

./auto/configure

由于 默认使用 http_rewrite_module,而 http_rewrite_module 依赖 PCRE library,因为未安装 PCRE library,因此 configure 出错:

./auto/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.

http_rewrite_module
rewrite 主要用于 url 地址重写以及重定向,即把 http 请求的 url 重定向到其他 url 的过程,或者给客户端返回 30x 重定向状态码。比如访问 baidu.com 就会转到访问 www.baidu.com ,或者返回 30x 重定向由客户端转向对 www.baidu.com 的访问。

PCRE library
PCRE 即 Perl Compatible Regular Expressions ,是一个采用C语言编写的正则表达式函数库,轻量、易用,性能优于POSIX正则表达式库和一些经典的正则表达式库(例如Boost正则表达式库)。

RCPE 被广泛使用在许多开源软件之中,例如 Apache HTTP服务器和Nginx等。

PCRE的C++实现版本是PCRE++。

http_rewrite_module 使用 PCRE library 对 url 进行正则匹配。

笔者暂时不需要使用 http_rewrite_module,因此采用 --without-http_rewrite_module 的配置选项,跳过对 http_rewrite_module 的依赖。

configure

./auto/configure --without-http_rewrite_module

由于默认使用 http_gzip_module,而 http_gzip_module 依赖 zlib library,因为未安装 zlib library,因此 configure 出错:

./auto/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.

http_gzip_module
http_gzip_module 是 nginx 的 http 压缩模块,对 http 响应进行压缩,可节约带宽,加快传输速度。

笔者暂时不需要使用 http_gzip_module ,因此采用 --without-http_gzip_module 的配置选项,跳过对 http_gzip_module 的依赖。

configure

./auto/configure --without-http_rewrite_module --without-http_gzip_module

configure 成功:

Configuration summary
  + PCRE library is not used
  + OpenSSL library is not used
  + zlib library is not used

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/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"

configure 成功后给出了 Configuration summary 并在 nginx 路径下生成一个 Makefile 文件。

编译

make && make install

验证是否成功:

[root@Nginx nginx]$ /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.20.2

启动配置

检查配置是否合法:

[root@Nginx nginx]$ /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启用 SSL 模块

./auto/configure --with-http_ssl_module --without-http_gzip_module

由于缺失 OpenSSL library 而报错

./auto/configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option

安装 OpenSSL library
https://www.openssl.org/source/

tar -zxvf openssl-1.1.1o.tar.gz 
cd openssl-1.1.1o
./config 
make

重新 configure nginx

./auto/configure --with-http_ssl_module --with-openssl=/root/openssl-1.1.1o --without-http_gzip_module
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容