首先确保机器中已安装 gcc c++,libtool等工具,保证可执行源码安装

A、为了确保能在 Nginx 中使用正则表达式进行更灵活的配置,安装之前需要确定系统是否安装有 PCRE(Perl Compatible Regular Expressions)包。您可以到 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:

1、解压:tar -zxvf pcre-8.34.tar.gz

2、切换到目录:cd pcre-8.34/

3、指定安装路径:./configure --prefix=/usr/local/pcre

4、编译并安装:make &&  make install

B、为了确保能在 Nginx 中使用URL重写模块,安装之前需要确定系统是否安装有 openssl包。您可以到http://www.openssl.org/source/ 下载适合自己系统的 openssl 源码包,使用下面命令下载编译和安装openssl包:

1、解压:tar -zxvf openssl-0.9.8y.tar.gz

2、切换到目录:cd ./openssl-0.9.8y/

3、指定安装路径:./configure --prefix=/usr/local/openssl  shared zlib-dynamic enable-camellia

4、编译并安装:make &&  make install

【PS:系统自带的openssl为其他软件的依赖项请勿轻易卸载】

使新安装的openssl发挥作用

a、将openssl安装路径加入到$PATH中:

  vi /etc/profile

  SSLPATH=/usr/local/openssl/bin  

  PATH=$SSLPATH:$PATH

export PATH

b、将路径/usr/bin/下openssl改名为openssl0.9.8(安装的软件包名)

切换到操作目录下(/usr/bin/):mv   openssl openssl 0.9.8

c、将/usr/local/openssl/include/openssl内容拷贝到/usr/include/下,并更名为openssl0.9.8

切换到操作目录下(/usr/include/):cp -r /usr/local/openssl/include/openssl  ./

C、开始安装nginx服务

1、解压:tar -zxvf nginx-1.4.7.tar.gz

2、切换到目录:cd ./nginx-1.4.7/

3、指定安装路径:./configure  \

--prefix=/usr/local/nginx-1.4.7  \

--sbin-path=/usr/sbin/nginx  \

          --conf-path=/etc/nginx/nginx.conf  \

          --error-log-path=/var/log/nginx/error.log  \

          --pid-path=/var/run/nginx/nginx.pid  \

          --lock-path=/var/lock/nginx.lock  \

          --user=nginx  \

            --group=nginx  \

          --with-http_ssl_module  \

          --with-http_flv_module  \

          --with-http_gzip_static_module  \

           --http-log-path=/var/log/nginx/access.log  \

         --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  \

         --with-http_stub_status_module  \

         --with-pcre=/home/andy/pcre-8.34  \

           --with-openssl=/home/andy/openssl-0.9.8y  \

           --with-zlib=/home/andy/zlib-1.2.8

[

    PS:注意事项。pcre,openssl,zlib依赖项的路径问题

  –with-pcre|--with-openssl|--with-zlib=DIR set path to PCRE library sources

  注意:set path to XX library sources是让你设置到源码目录,而不是编译安装后的目录。

]

4、编译并安装:make &&  make install

5、测试安装

  a、第一步:/usr/sbin/nginx -c /etc/nginx/nginx.conf  (提示/var/tmp/nginx/client目录不存在时,请自行建立该目录)

  b、第二步:nginx -c /etc/nginx/nginx.conf  (提示80端口已被占用,请先停止占用该端口的服务)

  c、第三步:ps -ef | grep nginx  (查看服务是否启动)

6、将nginx作为启动项的shell脚本

#!/bin/sh
 #
 # nginx - this script starts and stops the nginx daemon
 #
 # chkconfig: - 85 15
 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
 # proxy and IMAP/POP3 proxy server
 # processname: nginx
 # config: /etc/nginx/nginx.conf
 # config: /etc/sysconfig/nginx
 # pidfile: /var/run/nginx.pid

# Source function library.
 . /etc/rc.d/init.d/functions

# Source networking configuration.
 . /etc/sysconfig/network

# Check that networking is up.
 [ "$NETWORKING" = "no" ] && exit 0

pidfile=/var/run/nginx/nginx.pid
 nginx="/usr/sbin/nginx"
 prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/nginx.lock

make_dirs() {
 # make required directories
 user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
 options=`$nginx -V 2>&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/null 2>&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

使用chkconfig加载shell设置成服务:

  1. [root@localhost ~]# cp nginx /etc/init.d/nginx
  2. [root@localhost ~]# cd /etc/init.d
  3. [root@localhost init.d]# chmod 755 nginx
  4. [root@localhost init.d]# chkconfig --add nginx

下边启动nginx:

  1. [root@localhost init.d]# service nginx start
  2. Starting nginx:                                               [ok]

shell里还有其他的命令用起来都很方便,希望能帮助大家: 

redhat 5下源码安装nginx服务的更多相关文章

  1. Linux下源码安装Nginx服务

    nginx 安装 linux 系统需要安装必备的开发包,比如 gcc,gcc-c++     1. openssl (支持 https) https://www.openssl.org/source/ ...

  2. linux下源码安装apache服务

    1.搭建静态网站是,我们只需要搭建apache服务即可满足要求. 例如:如果我再客户端游览器输入地址,他会找到192.168.1.100这个服务器,然后根据端口会找到apache服务器.apache他 ...

  3. linux篇-linux下源码安装nginx

    LNMP模式 后续继续更新,先搭建nginx 安装环境gcc gcc-c++ 2 下载源码包解压 配置第一个报错 安装openssl openssl-devel yum -y install open ...

  4. CentOS 7下源码安装zabbix服务

    安装环境需要LAMP或者LNMP先搭建好 在此我使用上一篇搭建好的LNMP环境来安装zabbix 1.下载zabbix http://www.zabbix.com/download.php 2.安装及 ...

  5. nginx在Centos7.5下源码安装和配置

    安装nginx 安装nginx依赖包 yum install -y pcre-devel zlib-devel openssl-devel wget gcc tree vim 进入目录/root/se ...

  6. CentOS 7下源码安装MySQL 5.7

    网上说linux安装mysql服务分两种安装方法: ①源码安装,优点是安装包比较小,只有几十M左右,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错: ②使用官方编译好的二进制文件安装,优点 ...

  7. 源码安装nginx以及平滑升级

                                                           源码安装nginx以及平滑升级                               ...

  8. 在ConoHa上Centos7环境下源码安装部署LNMP

    本文记录了从源码,在Centos 7上手动部署LNMP环境的过程,为了方便以后对nginx和mariadb进行升级,这里采用yum的方式进行安装. 1.建立运行网站和数据库的用户和组 groupadd ...

  9. 源码安装Nginx以及用systemctl管理

    一.源码安装Nginx: 先安装gcc编译器(安装过的可以忽略) [root@localhost ~]# yum -y install gcc gcc-c++ wget 进入src目录 [root@l ...

随机推荐

  1. 转:Qt 嵌入式开发环境搭建

    地址: http://www.cnblogs.com/lishixian/articles/3013897.html         作者:lsx_007 这里主要是记录了自己在搭建嵌入式开发环境时阅 ...

  2. GridView 中Item项居中显示

    直接在GridView中设置 android:gravity="center"这个属性是不起作用的.要在你adapter中的布局文件中设 置android:layout_gravi ...

  3. 枚举类:用enum关键字来定义一个枚举类

    1)枚举类的两种定义方法 1>通过构造器 public enum Grade{ A("A", "90-100"),B("B",&quo ...

  4. JVM基础和调优(三)

    主要讲解垃圾回收的算法 上面我们已经了解到了,JVM的体系的结构,这次我们来说一下垃圾回收的算法. 1. 最开始的想法,或者说垃圾回收的最容易想到的就是:引用计数(reference count) 我 ...

  5. 哲学家用餐问题的几个解法(c语言实现)

    参考资料: 1.维基百科:哲学家用餐问题 2.Windows的多线程编程

  6. 第18讲- UI常用组件之EditText

    第18讲UI常用组件之EditText 三.文本输入框EditText EditTex类继承自TextView.EditText是接受用户输入信息的最重要控件.在html当中,相当于<input ...

  7. (转)iOS7界面设计规范(10) - UI基础 - 文字排版与配色

    明天就是周四了.貌似前几天还在恨周一呢.话说今天几乎开了一整天的会,正经事情没做多少:这种感觉比一整天从早到晚12个小时的忙碌于一件事情还要让人感到疲惫的对叭?那今天的iOS7设计规范更新又是一篇很简 ...

  8. ZigBee心电传输(一)

    第一次接触模拟的东西哈,也算是一次新的学习旅程以及对ZigBee的再一次探索吧. 首先是方案制定,以及采用芯片AD8232,这样节省了不少时间,把模拟的东西都搬到数字上了,不过还是需要学习不少模电知识 ...

  9. Win7x64安装Oracle11201x64 解决PLSQL Developer无法找到oci问题

    http://blog.sina.com.cn/s/blog_4c7628c40101cf56.html http://blog.csdn.net/shenkxiao/article/details/ ...

  10. (转)wcf client与webservice通信(-)只修改配置文件而改变服务端

    http://www.cnblogs.com/yiyisawa/archive/2008/12/16/1356191.html 问题: 假设有一个大型系统新版本使用wcf 作为服务端,生成wcf cl ...