Nginx编译安装:

时间:2021-12-15 18:23:37

第三方模块

在nginx.org   --------  wiki  找

--add-module=   添加

Nginx编译安装:

安装开发环境

]# yum groupinstall "Development Tools" "Server Platfrom Development"

安装组件

# yum install pcre-devel openssl-devel -y

编译安装

Tar  -zxvf  nginx.tgz

报错:/configure: error: C compiler cc is not found

Yum install gcc

./configure  --prefix=/usr/local/nginx  --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log  --http-log-path=/var/log/nginx/access.log  --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock  --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre

Make && make install

看unit文件

[Unit]

Description=The nginx HTTP and reverse proxy server

After=network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

PIDFile=/run/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 /run/nginx.pid

ExecStartPre=/usr/sbin/nginx -t

ExecStart=/usr/sbin/nginx

ExecReload=/bin/kill -s HUP $MAINPID

KillSignal=SIGQUIT

TimeoutStopSec=5

KillMode=process

PrivateTmp=true

[Install]

WantedBy=multi-user.target

添加启动:

systemctl daemon-reload

mkdir -p /var/cache/nginx/client_temp

chown nginx.nginx /var/cache/nginx

cp /usr/local/nginx/sbin/nginx  /usr/sbin/

Systemctl start  nginx.service

自己编译nginx  根据需求创建自己需要的rpm包

rpm -ivh nginx-1.10.2-1.el7.ngx.src.rpm

在root目录下生成rpmbutild目录

Nginx编译安装:

# vim nginx.spec  根据自己需要编译

# rpmbuild -bb nginx.spec

yum install rpmdevtools

会生成一个新的rpm包

http://nginx.org/packages/

源码编译安装的rpm包

先安装后根据自己的需求编译,生成新的rpm包