nginx 在ubuntu linux 源码安装 及配置

 1,准备环境

   A,首先确定你的系统装了 gcc,及 g++

   B, .安装pcre

         pcre-8.32 http://sourceforge.net/projects/pcre/files/pcre/  下载

           a, 解压 安装 tar -jxvf pcre-8.32.tar.bz2 

           b, cd pcre-8.32

           c, ./configure --prefix=/usr/local/pcre

           d, make

           e, make install


  --prefix=*** 是指定安装路径,不指定prefix,则可执行文件默认放在/usr /local/bin,库文件默认放在/usr/local b,配置文件默认放在/usr/local/etc。其它的资源文件放在/usr /local


 2.安装Nginx

      下载nginx-1.3.15.tar.gz,地址是:http://nginx.org/en/download.html

      a, tar   -zxvf   nginx-1.3.15.tar.gz

      b, cd   nginx-1.3.15

      c, ./configure \
 --prefix=/usr \
--sbin-path=/usr/local/nginx/sbin\
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx/nginx.pid \
--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


      关于configure 选项 参见点击打开链接    configure部分选项我们采用nginx 默认, 如果指定--prefix=/usr/local/nginx 等等

      会出现/usr/local/nginx目录下没有 sbin 目录

       d, make

       e, make install

    

    3, ./configure 及 make 会遇到的问题 .

        A, error: the HTTP cache module requires md5 functions
            from OpenSSL library.   You can either disable the module by using
           --without-http-cache option, or install the OpenSSL library into the system,
           or build the OpenSSL library statically from the source with nginx by using
           --with-http_ssl_module --with-openssl=<path> options.

       需要 安装 OpenSSL library

       方法:到 https://launchpad.net/ubuntu/precise/+source/openssl/1.0.1-4ubuntu3  下载openssl_1.0.1.orig.tar.gz  解压安装 即   可。

 

      B, ./configure: error: the HTTP gzip module requires the zlib library.
       You can either disable the module by using --without-http_gzip_module
        option, or install the zlib library into the system, or build the zlib library
        statically from the source with nginx by using --with-zlib=<path> option.


        下载zlib-1.2.5.tar.gz安装即可。


    C, 在configure完成之后执行make,出现了如下错误

    make -f objs/Makefile
    make[1]: Entering directory `/data/source/nginx'
    cd /usr/local/ufo/lib/pcre \
    && if [ -f Makefile ]; then make distclean; fi \
    && CC="gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
   ./configure --disable-shared
   /bin/sh: ./configure: No such file or directory
   make[1]: *** [/usr/local/services/lib/pcre/Makefile] Error 127
   make[1]: Leaving directory `/data/source/nginx-0.7.61'
   make: *** [build] Error 2

   从网上找到了解决方法:

  configure的时候指定pcre和openssl目录,要用pcre和openssl的源码,而不用已经安装好的pcre和openssl。。

  原因是查看nginx的configure --help |grep pcre,要求指定源码文件

  例如: home/wang/download/pcre-8.32 ,home/wang/download/openssl-1.0.1

 具体如下:

      ./configure  --with-pcre=/home/wang/download/pcre-8.32 --with-openssl=/home/wang/download/openssl-1.0.1

     这样重新make并make install就ok了!

  4,检查nginx是否安装成功

       a, cd  /usr/local/nginx/sbin

       b, ./nginx -t

      结果显示:
        nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
        nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

     启动nginx:

      a, cd  /usr/local/nginx/sbin 

      b, ./nginx

   或者这样检测

   输入:/usr/local/nginx/sbin/nginx

   Nginx默认以Deamon进程启动,输入下列命令:

   curl -i http://localhost/
  就可以检测Nginx是否已经成功运行。
  也可以用命令 curl -I http://localhost/查看我们此域名所使用的web服务器版本。
  启动后如果想停止Nginx可以使用:


 /usr/local/nginx/sbin/nginx -s stop
加入环境变量
 每次执行都要 写这么多/usr/local/nginx/sbin/nginx,嗯挺费事,现在我们把nginx的路径加入环境变量
  方法一:
 sudo  vim/etc/enviroment
 在PATH后的 = 后的字符串头部加入 /usr/local/nginx/sbin/nginx: 即可。
方法二:
 终端敲入命令:sudo  vim /etc/profile, 在最后一行加入
  PATH=/usr/local/nginx/sbin:$PATH
 编辑结束后执行命令:source profile
 

这样就把/usr/local/nginx/sbin/nginx 路径永久加入系统环境变量。
以后执行时直接 ngxin 即可。推荐方法一


ubuntu 中程序开机自启动 可以把命令放在文件 /etc/init.d/rc.local


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值