CentOS 6.7安装nginx

来源:互联网 发布:反美颜软件 编辑:程序博客网 时间:2024/05/17 13:13

nginx

编辑锁定

Nginx ("enginex")是一个高性能的HTTP反向代理服务器,也是一个IMAP/POP3/SMTP服务器Nginx是由Igor Sysoev俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004104日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名201161日,nginx 1.0.4发布。

Nginx是一款轻量级Web服务器/反向代理服务器及电子邮件IMAP/POP3)代理服务器,并在一个BSD-like协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度新浪网易腾讯等。

 

安装配置

 

1、 安装说明
系统环境:CentOS-6.7
软件:nginx-1.8.2.tar.gz
安装方式:源码编译安装
安装位置:/usr/local/nginx **默认安装**
下载地址:http://nginx.org/en/download.html

 

2、安装前提
在安装nginx前,需要确保系统安装了g++gccopenssl-develpcre-develzlib-devel软件。安装必须软件:
安装命令如下:
[root@localhost /]# yum install gcc-c++
[root@localhost /]# yum -y install zlib zlib-developenssl openssl-devel pcre pcre-devel

检查系统安装的Nginx
[root@localhost /]# find-name nginx
./usr/local/nginx/sbin/nginx

卸载原有的Nginx
[root@localhost /]# yum remove nginx

3、安装
将安装包文件上传到 /usr/local/nginx/中执行以下操作:
[root@localhost /]# cd /usr/local/nginx
[root@localhost nginx]# tar -zxvf nginx-1.8.2.tar.gz
[root@localhost nginx]# rm -rf nginx-1.2.6.tar.gz**
删除旧版**
[root@localhost nginx]# cd /usr/local/nginx-1.8.2
[root@localhost nginx-1.8.2]# ./configure -prefix=/usr/local/nginx-1.8.2
[root@localhost nginx-1.8.2]# make && makeinstall

之后在/etc/init.d/目录下创建一个nginx文件

Vi /etc/init.d/nginx

nginx文件中加入如下内容

#nx Startup script for the Nginx HTTPServer

# it is v.0.0.2 version.

# chkconfig: - 85 15

# description: Nginx is a high-performanceweb and proxy server.

#              It has a lot of features, butit's not for everyone.

# processname: nginx

# pidfile: /var/run/nginx.pid

# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx

nginx_config=/usr/local/nginx/conf/nginx.conf

nginx_pid=/var/run/nginx.pid

RETVAL=0

prog="nginx"

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ ${NETWORKING} = "no" ]&& exit 0

[ -x $nginxd ] || exit 0

# Start nginx daemons functions.

start() {

if [ -e $nginx_pid ];then

  echo "nginx already running...."

  exit 1

fi

  echo -n $"Starting $prog: "

  daemon $nginxd -c ${nginx_config}

  RETVAL=$?

  echo

   [$RETVAL = 0 ] && touch /var/lock/subsys/nginx

  return $RETVAL

}

# Stop nginx daemons functions.

stop() {

       echo -n $"Stopping $prog: "

       killproc $nginxd

       RETVAL=$?

       echo

       [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx/var/run/nginx.pid

}

# reload nginx service functions.

reload() {

   echo -n $"Reloading $prog: "

   #kill -HUP `cat ${nginx_pid}`

   killproc $nginxd -HUP

   RETVAL=$?

   echo

}

# See how we were called.

case "$1" in

start)

       start

       ;;

stop)

       stop

       ;;

reload)

       reload

        ;;

restart)

       stop

       start

       ;;

status)

       status $prog

       RETVAL=$?

       ;;

*)

       echo $"Usage: $prog {start|stop|restart|reload|status|help}"

       exit 1

esac

exit $RETVAL

 

*************************************************************

nginxd=/usr/local/nginx/sbin/nginx

nginx_config=/usr/local/nginx/conf/nginx.conf

nginx_pid=/var/run/nginx.pid

 

 

5、安装配置完成后要修改防火墙,不然无法访问 nginx
进入修改防火墙配置:
[root@localhost]# vi /etc/sysconfig/iptables
添加配置项:
-A INPUT -m state -state NEW -m tcp -p tcp -dport80 -j ACCEPT
重启防火墙:
[root@localhost]# service iptables restart

 

6、现在可以在浏览器中正常访问了,如下:

 

忘了一点,/etc/init.d/nginx 文件建立后要改写权限,直接 chmod 755 /etc/init.d/nginx 之后就可以 service nginx start 了, 同时要注意修改防火墙,不然也访问不了

0 0
原创粉丝点击