zl程序教程

您现在的位置是:首页 >  后端

当前栏目

CentOS4.0安装配置Nginx的方法

2023-06-13 09:15:31 时间

1.安装说明:

系统环境:CentOS-4.0

2.依赖的程序

   (1).gzipmodulerequireszliblibrary
   (2).rewritemodulerequirespcrelibrary
   (3).sslsupportrequiresopenssllibrary

3.依赖程序的安装有两种方法:一种是下载包安装二是YUM一次性安装

(1)zlib安装
   下载地址:http://zlib.net/fossils/
     $tar-xvzfzlib-1.2.5.tar.gz
     $cdzlib-1.2.5.tar.gz
     $./configure
     $make
     $makeinstall
(2)pcre安装
   下载地址:http://ftp.exim.llorien.org/pcre/
     $tar-xvzfpcre-8.02.tar.gz
     $cdpcre-8.02
     $./configure--prefix=/usr/local/pcre--enable-utf8--enable-unicode-properties
     $make&&makeinstall
(3)openssl安装
   下载地址:http://mirrors.ibiblio.org/openssl/source/
     $tarzvxfopenssl-1.0.0.tar.gz
     $cdopenssl-1.0.0
     $./config--prefix=/usr/local/ssl-1.0.0sharedzlib-dynamicenable-camellia
     $make&&makeinstall

(4)nginx安装

   下载地址:http://nginx.org/download/
     $tarzvxfNginx0.8.40.tar.gz
     $cdNginx0.8.40
     $./configure
     $make
     $makeinstall
    更多配置:
     ./configure--prefix=/usr/local/nginx
    --with-openssl=/usr/include(启用ssl)
    --with-pcre=/usr/include/pcre/(启用正规表达式)
    --with-http_stub_status_module(安装可以查看nginx状态的程序)
    --with-http_memcached_module(启用memcache缓存)
    --with-http_rewrite_module(启用支持url重写)
   方法二如下:这种方法就好,不容易出错,如果网速快10分内可以完成,网速不好也可以在20分内完成。
       yum?yinstallzlibzlib-developensslopenssl-develpcrepcre-devel
   现在三个依赖的程序的安装成功,下面是安装Nginx0.8.40了。

     官网下载地址:http://www.nginx.org/
     $tarzvxfNginx0.8.40.tar.gz
     $cdNginx0.8.40
     $./configure //默认安装在/usr/local/nginx下
     $make
     $makeinstall

4.配置(很重要)

复制代码代码如下:


   #修改防火墙配置:
   [root@bogonnginx-0.8.4]#vi+/etc/sysconfig/iptables
   #添加配置项
   -AINPUT-mstate--stateNEW-mtcp-ptcp--dport80-jACCEPT
   #重启防火墙
   [root@bogonnginx-0.8.4]#serviceiptablesrestart

5.启动:

复制代码代码如下:


   #方法1
   [root@bogonnginx-0.8.4]#/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf
   #方法2
   [root@bogonnginx-0.8.4]#cd/usr/local/nginx/sbin
   [root@bogonsbin]#./nginx

6.停止:

复制代码代码如下:
   #查询nginx主进程号
   ps-ef|grepnginx
   #停止进程
   kill-QUIT主进程号
   #快速停止
   kill-TERM主进程号
   #强制停止
   pkill-9nginx

7.测试:

复制代码代码如下:
   #测试端口
   netstat?na|grep80
   #浏览器中测试
   http://127.0.0.1:80

8.注意问题:
   安装nginx时出现情况的解决办法:

复制代码代码如下:
   [root@bogonsbin]#./nginx
   [emerg]:bind()to0.0.0.0:80failed(98:Addressalreadyinuse)
   [emerg]:bind()to0.0.0.0:80failed(98:Addressalreadyinuse)
   [emerg]:bind()to0.0.0.0:80failed(98:Addressalreadyinuse)
   [emerg]:bind()to0.0.0.0:80failed(98:Addressalreadyinuse)
   [emerg]:bind()to0.0.0.0:80failed(98:Addressalreadyinuse)
   [emerg]:stillcouldnotbind()

   #netstat-nptl //查看80端口已被使用
   #killallnginx //即可