Linux下源码安装Nginx1.6

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:838

一、文件说明 [size=14px] [font=Tahoma, sans-serif][size=14px]pcre[size=14px]支持[font=Tahoma, sans-serif][size=14px]nginx[size=14px]伪静态openssl(nginx扩展)zlib(nginx扩展)软件源代码包存放位置:/usr/local/src源码包编译安装位置:/usr/local/软件名字二、安装编译工具及库文件将centos.repo文件放入到/etc/yum.repos.d/目录下[root@ wanzhuangit]# [font=Tahoma, sans-serif]yum install -y apr* autoconf automake bison bzip2 bzip2*cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetypefreetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibckernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devellibpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devellibtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfrncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gdpolicycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel三、安装步骤[font=Tahoma, sans-serif]1、安装[font=Tahoma, sans-serif]pcre[root@v19 nginx_package]# mkdir -p/usr/local/pcre[root@v19 nginx_package]# tar zxvfpcre-8.36.tar.gz -C /usr/local/src/[root@v19 nginx_package]# cd /usr/local/src[root@v19 src]# cd pcre-8.36/[root@v19 pcre-8.36]# ./configure--prefix=/usr/local/pcre[root@v19 pcre-8.36]# make[root@v19 pcre-8.36]# make install[font=Tahoma, sans-serif]2、安装[font=Tahoma, sans-serif]openssl[font=Tahoma, sans-serif][root@v19 nginx_package]# mkdir/usr/local/openssl[font=Tahoma, sans-serif][root@v19 nginx_package]# tarzxvf openssl-1.0.1h.tar.gz -C /usr/local/src/[font=Tahoma, sans-serif][root@v19 nginx_package]# cd/usr/local/src/openssl-1.0.1h/[font=Tahoma, sans-serif][root@v19 openssl-1.0.1h]#./config --prefix=/usr/local/openssl[font=Tahoma, sans-serif][root@v19 openssl-1.0.1h]# make [font=Tahoma, sans-serif][root@v19 openssl-1.0.1h]# makeinstall编辑 [font=Tahoma, sans-serif]/etc/profile文件[font=Tahoma, sans-serif] 添加一些内容[font=Tahoma, sans-serif]export PATH=$PATH:/usr/local/openssl/bin[img=480,35]file:///C:/Users/xiaozhu/AppData/Local/Temp/msohtmlclip1/01/clip_image002.jpg[/img][font=Tahoma, sans-serif][root@v19 openssl-1.0.1h]#source /etc/profile[font=Tahoma, sans-serif]3、安装[font=Tahoma, sans-serif]zlib[font=Tahoma, sans-serif][root@v19 nginx_package]# mkdir/usr/local/zlib[font=Tahoma, sans-serif][root@v19 nginx_package]# tarzxvf zlib-1.2.8.tar.gz -C /usr/local/src/[root@v19 nginx_package]# cd/usr/local/src/zlib-1.2.8/[root@v19 zlib-1.2.8]# ./configure--prefix=/usr/local/zlib[root@v19 zlib-1.2.8]# make[root@v19 zlib-1.2.8]# make install[font=Tahoma, sans-serif]4、安装[font=Tahoma, sans-serif]Nginx[root@v19 nginx_package]# groupadd www[root@v19 nginx_package]# useradd -g wwwwww -s /bin/false[root@v19 nginx_package]# tar zxvfnginx-1.6.0.tar.gz -C /usr/local/src[root@v19 nginx_package]# cd/usr/local/src/[root@v19 nginx-1.6.0]# ./configure--prefix=/usr/local/nginx --without-http_memcached_module --user=www--group=www --with-http_stub_status_module --with-http_ssl_module--with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1h--with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36注意:[font="]--with-openssl=/usr/local/src/openssl-1.0.1h--with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36指向的是源码包解压的路径,而不是安装的路径,否则会报错[root@v19 nginx-1.6.0]# make [root@v19 nginx-1.6.0]# make install[root@v19 nginx-1.6.0]#/usr/local/nginx/sbin/nginx [font=Tahoma, sans-serif]#启动[font=Tahoma, sans-serif]Nginx设置nginx开机启动vi /etc/rc.d/init.d/nginx #编辑启动文件添加下面内容#############################################################!/bin/sh## nginx - this scriptstarts and stops the nginx daemon## chkconfig: - 85 15# description: Nginx isan HTTP(S) server, HTTP(S) reverse \# proxy and IMAP/POP3proxy server# processname: nginx# config:/etc/nginx/nginx.conf# config:/usr/local/nginx/conf/nginx.conf # pidfile:/usr/local/nginx/logs/nginx.pid# Source functionlibrary. ./etc/rc.d/init.d/functions # Source networkingconfiguration. . /etc/sysconfig/network # Check that networkingis up. [ "$NETWORKING"= "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() { # make requireddirectories user=`$nginx -V2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^]*\).*/\1/g' -` if [ -z "`grep $user/etc/passwd`" ]; then useradd -M -s/bin/nologin $user fi options=`$nginx -V2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep'.*-temp-path'` ]; then value=`echo $opt | cut -d"=" -f 2` if [ ! -d"$value" ]; then # echo"creating" $value mkdir -p $value&& chown -R $user $value fi fi done } start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ]|| exit 6 make_dirs echo -n $"Starting$prog: " daemon $nginx -c$NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ]&& touch $lockfile return $retval } stop() { echo -n $"Stopping$prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ]&& rm -f $lockfile return $retval } restart() { #configtest || return $? stop sleep 1 start } reload() { #configtest || return $? echo -n $"Reloading$prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c$NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null2>&1 } case "$1" in start) rh_status_q &&exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac ############################################################[root@v19 nginx-1.6.0]# chmod 775/etc/rc.d/init.d/nginx [font=Tahoma, sans-serif]#赋予文件执行权限[root@v19 nginx-1.6.0]# chkconfig nginx on [font=Tahoma, sans-serif]#设置开机启动[root@v19 nginx-1.6.0]#/etc/rc.d/init.d/nginx restart [font=Tahoma, sans-serif]#重启[img=553,228]file:///C:/Users/xiaozhu/AppData/Local/Temp/msohtmlclip1/01/clip_image004.jpg[/img]

本文标签:
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】