Centos6.5安装配置nginx

15670次浏览

我也是第一次安装nginx,现在将我的安装方法记录下来:

方法一:安装最新版的nginx

1、下载nginx1.7.4

注:下载地址:http://nginx.org/download/nginx-1.7.4.tar.gz

wget -c http://nginx.org/download/nginx-1.7.4.tar.gz  

2、安装

注:默认安装到/usr/local/nginx

tar -zxvf nginx-1.7.4.tar.gz   
cd nginx-1.7.4   
./configure    
make && make install #注:会出来一堆东西  

3、运行

/usr/local/nginx/sbin/nginx

查看nginx是否正常

[root@aaa nginx-1.2.4]# /usr/local/nginx/sbin/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,(参考我同事的安装方法) 安装 OpenSSL(方法自行搜索,或者yum install openssl) 准备 pcre 库 pere 是为了让 nginx 支持正则表达式。只是准备,并不安装,是为了避免在64位系统中出现错误。

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
//在/usr/local目录下解压
tar -zxf pcre-8.30

准备 zlib 库,同样只是准备,并不安装,是为了避免在64位系统中出现错误。

wget http://sourceforge.net/projects/libpng/files/zlib/1.2.6/zlib-1.2.6.tar.gz/download
//在/usr/local目录下解压
tar -zxf zlib-1.2.6.tar.gz

编译安装

1、下载、创建临时目录

wget http://nginx.org/download/nginx-1.1.9.tar.gz
tar -zxf nginx-1.1.9.tar.gz
cd nginx-1.1.9
mkdir -p /var/tmp/nginx

2、编译与安装

./configure --prefix=/usr/local/nginx \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-http_ssl_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-mail --with-mail_ssl_module \
--with-pcre=../pcre-8.30 \
--with-zlib=../zlib-1.2.6 \
--with-debug \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi 

make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/

可参考:Nginx编译参数解析

–prefix #nginx安装目录,默认在/usr/local/nginx
–pid-path #pid问件位置,默认在logs目录
–lock-path #lock问件位置,默认在logs目录
–with-http_ssl_module #开启HTTP SSL模块,以支持HTTPS请求。
–with-http_dav_module #开启WebDAV扩展动作模块,可为文件和目录指定权限
–with-http_flv_module #支持对FLV文件的拖动播放
–with-http_realip_module #支持显示真实来源IP地址
–with-http_gzip_static_module #预压缩文件传前检查,防止文件被重复压缩
–with-http_stub_status_module #取得一些nginx的运行状态
–with-mail #允许POP3/IMAP4/SMTP代理模块
–with-mail_ssl_module #允许POP3/IMAP/SMTP可以使用SSL/TLS
–with-pcre=../pcre-8.11 #注意是未安装的pcre路径
–with-zlib=../zlib-1.2.5 #注意是未安装的zlib路径
–with-debug #允许调试日志
–http-client-body-temp-path #客户端请求临时文件路径
–http-proxy-temp-path #设置http proxy临时文件路径
–http-fastcgi-temp-path #设置http fastcgi临时文件路径
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #设置uwsgi 临时文件路径
–http-scgi-temp-path=/var/tmp/nginx/scgi #设置scgi 临时文件路径

3、开机自启动 nginx 脚本

vim /etc/init.d/nginx

进入编辑模式,键入以下脚本内容:

#!/bin/bash  
#  
#chkconfig: - 85 15  
#description: Nginx is a World Wide Web server.  
#processname: nginx  

nginx=/usr/local/nginx/sbin/nginx  
conf=/usr/local/nginx/conf/nginx.conf  

case $1 in  
       start)  
              echo -n "Starting Nginx"  
              $nginx -c $conf  
              echo " done"  
       ;;  

       stop)  
              echo -n "Stopping Nginx"  
              killall -9 nginx  
              echo " done"  
       ;;  

       test)  
              $nginx -t -c $conf  
       ;;  

        reload)  
              echo -n "Reloading Nginx"  
              ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP  
              echo " done"  
       ;;  

        restart)  
                $0 stop  
                $0 start  
       ;;  

       show)  
              ps -aux|grep nginx  
       ;;  

       *)  
              echo -n "Usage: $0 {start|restart|reload|stop|test|show}"  
       ;;  

esac

保存以上脚本后,执行以下操作

chmod +x /etc/init.d/nginx
chkconfig --add nginx  
chkconfig nginx on 

可以使用nginx -t来检验语法是否有问题。

Tags: linuxnginx

相关文章: