1. 程式人生 > >nginx編譯安裝

nginx編譯安裝

nginx編譯安裝 nginx啟動腳本 nginx1.12編譯安裝

Nginx編譯安裝

Linux系統下Nginx的源碼編譯安裝模塊依賴性,需要依賴下面3個安裝包(下面的演示版本不是最新版本,你也可以下載最新的版本,只要把版本號修改一下即可):

一般yum安裝以下幾個插件:

yum -y install pcre-devel zlib-devel openssl openssl-devel

但這裏我們選擇編譯安裝:

1:ssl 功能需要 openssl 庫 ( 下載:http://www.openssl.org/source)

wget http://www.openssl.org/source/openssl-fips-1.0.2l.tar.gz

2:gzip 模塊需要 zlib 庫 ( 下載:http://www.zlib.net/)

wget http://zlib.net/zlib-1.2.11.tar.gz

3:rewrite 模塊需要 pcre 庫 ( 下載:http://www.pcre.org/ )

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz


############## 一、安裝OpenSSL ######################

下載地址 https://www.openssl.org/source/

wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
tar zxvf openssl-1.0.2l.tar.gz
cd openssl-1.0.2l/
./config --prefix=/usr/ --openssldir=/usr/ shared;
 make && sudo make install


################ 二、安裝PCRE ########################
下載地址 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
tar zxvfpcre-8.41.tar.gz
./configure --prefix=/opt/pcre-8.41 ;
 make && sudo make install


################ 三、安裝ZLIB ########################

tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install


################ 三、安裝Nginx ########################

下載Nginx源碼包(stable version)

wget http://nginx.org/download/nginx-1.12.2.tar.gz

創建用戶與組:

groupadd nginx
useradd -s /sbin/nologin -g nginx -M nginx

解壓

tar -zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2/

配置編譯環境(--with-pcre、--with-openssl的路徑是源碼路徑,pcre、openssl的安裝路徑在/opt,但這裏只需要源碼路徑)

./configure --prefix=/opt/nginx --user=nginx --group=nginx --error-log-path=/opt/nginx/logs/nginx/error.log --http-log-path=/opt/nginx/logs/nginx/access.log --pid-path=/opt/nginx/run/nginx/nginx.pid --lock-path=/opt/nginx/var/lock/nginx.lock --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=../pcre-8.41 --with-openssl (#編譯路徑指定--with-openssl=/opt/openssl-1.0.21)


#以上編譯安裝nginx後,--http-client-body-temp-path、--http-proxy-temp-path、--http-fastcgi-temp-path、--http-uwsgi-temp-path、--http-scgi-temp-path默認的路徑就在/usr/local/nginx下,分別是client_body_temp、proxy_temp、fastcgi_temp、scgi_temp、uwsgi_temp


make && make install
添加一個nginx主程序的符號鏈接ln -s /web/nginx/sbin/nginx /usr/local/sbin/


配置參數描述:

--with-xxx 代表默認沒有打開的功能
--without-xxx 代表默認打開的功能

--prefix=path 代表安裝路徑
--sbin-path=path sbin路徑
--conf-path 配置文件
--pid-path 代表進程號保存文件
--error-log-path錯誤日誌
--lock-path 鎖文件
--user ps看到的啟動進程用戶
--group ps看到的啟動進程用戶所在組
--with-http_ssl_module
--with-http_flv_module


將nginx加入service來管理啟動與停止:

vi /etc/init.d/nginx
#!/bin/bash
# nginx 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: /opt/nginx/conf/nginx.conf
nginxd=/opt/nginx/sbin/nginx
nginx_config=/opt/nginx/conf/nginx.conf
nginx_pid=/opt/nginx/run/nginx/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 $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
 echo "nginx already running...."
 exit 1
fi
 echo -n $"Starting $prog: "
 daemon $nginxd -c ${nginx_config}
 RETVAL=$?
 echo
 [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
 return $RETVAL
}
# Stop nginx daemons functions.
stop() {
 echo -n $"Stopping $prog: "
 killproc $nginxd
 RETVAL=$?
 echo
 [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /opt/nginx/run/nginx/nginx.pid #這裏也要註意修改你的nginx的pid路徑
}
# reload nginx service functions.
reload() {
 echo -n $"Reloading $prog: "
 killproc $nginxd -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

chmo +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
chkconfig --list nginx
nginx           0:關閉  1:關閉  2:啟用  3:啟用  4:啟用  5:啟用  6:關閉


本文出自 “運維筆錄 美玲” 博客,請務必保留此出處http://meiling.blog.51cto.com/6220221/1978442

nginx編譯安裝