CentOS7源码编译的nginx1.14.0完整版

本文详细介绍了如何从源码安装Nginx及其依赖,并提供了详细的配置步骤,包括用户组设置、模块选择、路径配置等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、安装预备

1、到官网下个nginx源码包【传送门:http://nginx.org/en/download.html

2、装依赖

yum -y install pcre pcre-devel
yum -y install openssl openssl-devel
yum -y install gcc-c++ autoconf automake
yum install -y zlib-devel
yum -y install libxml2 libxml2-dev
yum -y install libxslt-devel
yum -y install gd-devel
yum -y install perl-devel perl-ExtUtils-Embed
yum -y install GeoIP GeoIP-devel GeoIP-data

3、建用户及用户组

groupadd nginx
useradd -g nginx nginx

4、扩展说明

1、指定已安装的第三方模块目录,比如https的支持等 ** --add-module=/usr/local/nginx/extra/modules --add-dynamic-module=/usr/local/nginx/extra/dynamic-modules **

如果没加这两个参数可以后期重新./configure和make不需要make install因为会覆盖 【参考文章:https://blog.youkuaiyun.com/cxm19881208/article/details/64441890

2、google优化工具: *--with-google_perftools_module * 需要安装libunwind才可以,平时开发环境可以不用打开此项,装起来有点麻烦,需要的自行google或度娘

3、编译安装遇到了问题? 参考文章:https://tieba.baidu.com/p/4568751779?red_tag=0918228242

二、编译安装

1、./configure(建议./configure --help看一遍)

./configure --prefix=/usr/local/nginx \
  --sbin-path=/usr/local/sbin/nginx \
  --modules-path=/usr/local/nginx/modules \
  --conf-path=/usr/local/nginx/etc/nginx.conf \
  --error-log-path=/usr/local/nginx/error.log \
  --pid-path=/usr/local/nginx/run/nginx.pid \
  --lock-path=/usr/local/nginx/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-select_module \
  --with-poll_module \
  --with-threads \
  --with-file-aio \
  --with-http_ssl_module \
  --with-http_v2_module \
  --with-http_realip_module \
  --with-http_addition_module \
  --with-http_xslt_module \
  --with-http_xslt_module=dynamic \
  --with-http_image_filter_module \
  --with-http_image_filter_module=dynamic \
  --with-http_geoip_module \
  --with-http_geoip_module=dynamic \
  --with-http_sub_module \
  --with-http_dav_module \
  --with-http_flv_module \
  --with-http_mp4_module \
  --with-http_gunzip_module \
  --with-http_gzip_static_module \
  --with-http_auth_request_module \
  --with-http_random_index_module \
  --with-http_secure_link_module \
  --with-http_degradation_module \
  --with-http_slice_module \
  --with-http_stub_status_module \
  --http-log-path=/usr/local/nginx/access.log \
  --http-client-body-temp-path=/usr/local/nginx/http/client-body \
  --http-proxy-temp-path=/usr/local/nginx/http/proxy \
  --http-fastcgi-temp-path=/usr/local/nginx/http/fastcgi \
  --http-uwsgi-temp-path=/usr/local/nginx/http/uwsgi \
  --http-scgi-temp-path=/usr/local/nginx/http/scgi \
  --with-mail \
  --with-mail=dynamic \
  --with-mail_ssl_module \
  --without-mail_pop3_module \
  --without-mail_imap_module \
  --without-mail_smtp_module \
  --with-stream \
  --with-stream=dynamic \
  --with-stream_ssl_module \
  --with-stream_realip_module \
  --with-stream_geoip_module \
  --with-stream_geoip_module=dynamic \
  --with-stream_ssl_preread_module \
  --with-cpp_test_module \
  --with-compat \
  --with-debug

2、看到如下信息说明编译成功

Configuration summary
  + using threads
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/sbin"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/etc"
  nginx configuration file: "/usr/local/nginx/etc/nginx.conf"
  nginx pid file: "/usr/local/nginx/run"
  nginx error log file: "/usr/local/nginx/logs"
  nginx http access log file: "/usr/local/nginx/http/log"
  nginx http client request body temporary files: "/usr/local/nginx/http/client-body-temp-path"
  nginx http proxy temporary files: "/usr/local/nginx/http/proxy-temp-path"
  nginx http fastcgi temporary files: "/usr/local/nginx/http/fastcgi-temp-path"
  nginx http uwsgi temporary files: "/usr/local/nginx/http/uwsgi-temp-path"
  nginx http scgi temporary files: "/usr/local/nginx/http/scgi-temp-path"

3、编译安装

make &make install

4、看到如下输出信息安装完成

make[1]: Leaving directory `/usr/local/src/nginx-1.14.0'
[1]+  Done                    make

5、由于./configure的时候已经制定了sbin的path,所以不要再人为软链到sbin,如果which nginx找不到,请自行加入ln -s软链

6、测试一下并寻找nginx的配置文件位置

nginx -t

7、检查

id nginx

8、指定配置文件

nginx -c /usr/local/nginx/etc/nginx.conf

9、平滑重启

nginx -s reload

10、可能报错没什么目录,根据提示建一个就好,上面configure的时候配置http的client-body

mkdir -p /usr/local/nginx/http/client-body
nginx -s reload

转载于:https://my.oschina.net/cxgphper/blog/2050510

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值