nginx的编译安装

本文介绍了如何手动编译安装nginx,包括下载nginx源码、配置参数如http_ssl_module、pcre、zlib和openssl,解决编译错误,修改Makefile,成功编译后创建快捷方式到/usr/bin,并创建启动脚本。同时,文章强调了配置文件中的include指令和为nginx创建用户及用户组的重要性。

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

nginx下载网站 http://nginx.org/ http://nginx.org/en/download.html > http://nginx.org/download/nginx-1.15.8.tar.gz
cd nginx-1.15.8
./configure --sbin-path=/usr/local/nginx/nginx
–conf-path=/usr/local/nginx/nginx.conf
–pid-path=/usr/local/nginx/nginx.pid
–with-http_ssl_module
–with-pcre=/root/pcre-8.37 #pcre指定源程序 是为了开启重写 rewrite
–with-zlib=/usr/local/zlib-1.2.8 #zlib指定编译的路径 是为了开启gzip
–with-openssl=/usr/local/openssl-1.0.2q #openssl也制定编译后的路径

pcre支持包 https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz 之前下载最新版的pere2报错,换成pcre版本后不报错
make[1]: *** [/usr/local/pcre//Makefile] Error 127 --with-pcre//Makefile 指向源程序目录
make[1]: *** [/usr/local/openssl//.openssl/include/openssl/ssl.h] Error 127 修改nginx源程序中auto lib openssl conf 中.openssl使他的路径中不重复openssl名称。
make[1]: *** [objs/src/http/modules/ngx_http_log_module.o] Error 1 修改nginx原目录下objc下的Makefile 去掉-Werror
后编译成功
zlib下载网址http://www.zlib.net/zlib-1.2.11.tar.gz
openssl https://www.openssl.org/source/ https://www.openssl.org/source/openssl-1.0.2q.tar.gz
nginx成功编译后
pcre是源目录
zlib是源目录
openssl是编译后的目录
make && make install 后
需要将nginx的运行程序创建快捷方式到usr/bin 中 ln -s 源文件名称 快捷文件名称
创建启动脚本

注意路径

#!/bin/bash
#nx Startup script for the Nginx HTTP Server

# it is v.0.0.2 version.

# chkconfig: - 85 15

# description: Nginx is a high-performance web and proxy server.

#              It has a lot of features, but it's not for everyone.

# processname: nginx

# pidfile: /var/run/nginx.pid

# config: /usr/local/nginx/conf/nginx.conf

nginx=/opt/nginx/nginx

nginx_config=/opt/nginx/conf/nginx.conf

nginx_pid=/var/run/nginx.pid

RETVAL=0

prog="nginx"

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ ${NETWORKING} = "no" ] && exit 0

[ -x $nginx ] || exit 0

# Start nginx daemons functions.

start() {

if [ -e $nginx_pid ];then

   echo "nginx already running...."

   exit 1

fi

   echo -n $"Starting $prog: "

   daemon $nginx -c ${nginx_config}

   RETVAL=$?

   echo

   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx

   return $RETVAL

}

# Stop nginx daemons functions.

stop() {

        echo -n $"Stopping $prog: "

        killproc $nginx

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid

}

# reload nginx service functions.

reload() {

    echo -n $"Reloading $prog: "

    #kill -HUP `cat ${nginx_pid}`

    killproc $nginx -HUP

    RETVAL=$?

    echo

}

# See how we were called.

case "$1" in

start)

        start

        ;;

stop)

        stop

        ;;

reload)

        reload

        ;;

restart)

        stop

        start

        ;;

status)

        status $prog

        RETVAL=$?

        ;;

*)

        echo $"Usage: $prog {start|stop|restart|reload|status|help}"

        exit 1

esac

exit $RETVAL

此时的nginx.conf文件并没有开启include
include extra/www.conf;
include /opt/nginx/*.conf
创建一个nginx用户和用户组,将/opt目录下的nginx全部改变所属用户和组
useradd nginx -g nginx -s /sbin/nologin -d /var/webroot/
chown -R nginx nginx/
chgrp -R nginx nginx/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值