nginx的編譯安裝

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/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章