一、nginx 编译安装 模块添加删除 第三方模块添加删除

nginx安装

wget http://nginx.org/download/nginx-1.17.1.tar.gz
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate gcc gcc-c++ glibc glibc-devel \
pcre pcre-devel openssl openssl-devel systemd-devel net- tools iotop bc zip unzip zlib-devel \
bash-completion nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed

useradd nginx -s /sbin/nologin -M
yum repolist
rpm -qa pcre pcre-devel
rpm -qa openssl-devel openssl
yum install pcre pcre-devel
yum install openssl-devel openssl
yum install -y zlib zlib-devel
yum install -y gcc-c++ #pcre编译安装需要gcc。
# yum install gcc pcre-devel openssl-devel zlib-devel perl-ExtUtils-Embed
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --error-log-path=/storage/nginx/logs/error.log --http-log-path=/storage/nginx/logs/access.log --with-openssl=/usr/local/openssl_1.1.1a --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-poll_module

make
make install
命令启动和开机启动
ln -s /xxx/nginx/sbin/nginx /usr/sbin/
chown nginx.nginx -R /usr/local/nginx
vim /etc/rc.d/rc.local chmod +x
/usr/sbin/nginx



cat /usr/lib/systemd/system/nginx.service

[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 


systemctl daemon-reload
systemctl enable nginx.service
systemctl start nginx.service

================================================================================================================================
nginx加载模块 (编译安装后的nginx添加新的nginx模块和第三方法模块,)
1.下载同一版本的nginx.和第三方法模块
2.查看nginx版本和模块信息
[root@localhost ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.17.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log
--with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-poll_module

3.添加和删除模块。
[root@localhost ~]# cd /usr/local/nginx-1.17.
[root@localhost nginx-1.17.1]# ./configure --help #查看说明
[root@localhost nginx-1.17.1]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log
--with-http_stub_status_module
--with-http_ssl_module
--with-http_gzip_static_module
--with-poll_module
--add-module=/usr/local/nginx-1.17.1/nginx-rtmp-module-1.2.1 #添加第三方法模块 ,第三模块要和源码在同一文件下,添加第三方法需要--add-module=/PATH
--without-http_access_module #删除nginx模块, --without开头的,默认是启用的(不想启用此模块时,可以在编译的时候加上这个参数)
--with-http_addition_module #添加nginx模块 , -with开头的,默认是禁用的(想使用的话需要在编译的时候加上)

make #执行编译,记住不要make install 安装

4.编译后备份和移动的nginx在当前目录的objs文件夹内。(注意,复制和移动先把nginx服务stop, 可能会不让复制)
[root@localhost nginx-1.17.1]#/usr/local/nginx/sbin/nginx -s stop
[root@localhost nginx-1.17.1]#cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
5. ./configure下的objs文件夹中nginx复制。
[root@localhost nginx-1.17.1]#cp objs/nginx /usr/local/nginx/sbin/
[root@localhost nginx-1.17.1]#/usr/local/nginx/sbin/nginx #启动
6.再查看版本
[root@localhost ~]# /usr/local/nginx/sbin/nginx -V


==========================================================================================================

实验:nginx 第三方模块
第三模块是对nginx 的功能扩展,第三方模块需要在编译安装nginx 的时候使用参数--add-module=PATH指定路径添加,有的模块是由公司的开发人员针对业务需求定制
开发的,有的模块是开源爱好者开发好之后上传到github进行开源的模块,nginx支持第三方模块,需要重新编译源码才能支持
开源的echo模块,实现输出变量等信息
https://github.com/openresty/echo-nginx-module
示例:
#yum install git –y
#cd /usr/local/src
#git clone https://github.com/openresty/echo-nginx-module.git
#cd nginx-1.16.0/
#useradd –r –s /sbin/nologin nginx
#yum install gcc pcre-devel openssl-devel zlib-devel perl-ExtUtils-Embed

#

./configure \
--prefix=/usr/local/nginx \
--error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log \
--user=nginx --group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_perl_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--add-module=/usr/local/nginx/modules/echo-nginx-module-master \
--with-openssl=/usr/local/src/openssl_1.1.1d #先下载openssl_1.1.1d

 


# make && make install

使用nginx -V 查看模块和openssl版本

posted @ 2022-07-07 15:17  yuanbangchen  阅读(953)  评论(0编辑  收藏  举报