1. 云栖社区>
  2. PHP教程>
  3. 正文

linux环境下nginx安装

作者:用户 来源:互联网 时间:2017-11-30 15:14:06

linux安装nginx环境

linux环境下nginx安装 - 摘要: 本文讲的是linux环境下nginx安装,linux环境下nginx安装下载nginx源码地址 http://download.csdn.net/download/a51561/100376811.解压nginx源码tar -zvxf nginx-1.12.1.tar.gz2.加载

linux环境下nginx安装

下载nginx源码地址

http://download.csdn.net/download/a51561/10037681

1.解压nginx源码
tar -zvxf nginx-1.12.1.tar.gz
2.加载依赖包
yum install gcc-c++
yum install -y zlib-devel
yum -y install pcre-devel
yum -y install openssl openssl-devel 
3.配置。通常将软件安装在/usr/local/目录下
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
4.编译和安装
make && make install
5.检验是否安装成功
cd /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
 6. 配置防火墙80端口
    #修改防火墙配置: 
    # vi + /etc/sysconfig/iptables
    #添加配置项 
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
    #重启防火墙 
    # service iptables restart
将nginx设置成开机启动项
1.添加新服务文件
vi /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server


# it is v.0.0.2 version.


# chkconfig: - 85 15


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


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


# processname: nginx


# pidfile: /var/run/nginx.pid


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


nginxd=/user/local/nginx/sbin/nginx


nginx_config=/user/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


}


# 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
2.添加服务
chkconfig --add nginx
3.查看服务列表
chkconfig --list nginx  (如果显示情况 3:关闭(off) 4:关闭(off) 5:关闭(off))
4.开启服务
chkconfig --level 345 nginx on




nginx配置添加php环境
1.修改配置文件
vi /usr/local/nginx/config/nginx.conf
在66行将注释放开
location ~ /.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    2.重新启动nginx服务器
    service nginx restart

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索linux , 安装 , nginx 环境 ,以便于您获取更多的相关知识。