Centos 6.5 Nginx 快速部署

来源:互联网 发布:js获取option选中的值 编辑:程序博客网 时间:2024/04/30 06:23
依赖包安装
yum install zlib pcre pcre-devel openssl openssl-devel -y

yum install gcc -y

yum install gcc-c++ -y

创建nginx用户
useradd -s /sbin/nologin nginx

下载nginx
wget http://nginx.org/download/nginx-1.10.0.tar.gz

解压nginx
tar -zxvf nginx-1.10.0.tar.gz

cd / nginx-1.10.0
./configure \
--user=nginx \
--group=nginx \
--prefix=/opt/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/tmp/nginx/client_body \
--http-proxy-temp-path=/tmp/nginx/proxy \
--http-fastcgi-temp-path=/tmp/nginx/fastcgi \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/subsys/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre \
--with-http_realip_module \
--with-http_sub_module

make
make install

#########################################################################################
Nginx 编译参数
--user            指定启动程序所属用户
--group          指定组
--prefix          指定安装路径
--sbin-path    设置nginx二进制文件的路径名
--conf-path    指定配置文件路径
--error-log-path    错误日志文件路径
--http-log-path    指定访问日志文件路径
--http-client-body-temp-path    设置存储HTTP客户端请求主体的临时文件路径
--http-proxy-temp-path            设置存储HTTP代理临时文件的路径
--http-fastcgi-temp-path          设置存储HTTP fastcgi的临时文件的路径
--pid-path          设置nginx.pid文件路径
--lock-path        设置nginx.lock文件路径
--with-openssl    启用SSL
--with-pcre        启用正则表达式
--with-http_stub_status_module    安装可以监控nginx状态的模块
--with-http_ssl_module                启用SSL支持
--with-http_gzip_static_module    启用gzip压缩
#########################################################################################

nginx端口状态
netstat -ntlp | grep nginx


控制nginx服务的命令
1、启动:nginx
2、停止:nginx -s stop
3、退出:nginx -s quit
4、重启:nginx -s reopen
5、重新加载:nginx -s reload
6、平滑启动:kill -HUP pid(kill -HUP `cat /var/run/nginx.pid`)


创建nginx自启动脚本
vi /etc/init.d/nginx
 
#!/bin/bash
# chkconfig: - 18 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
 
NGINX_SBIN="/usr/sbin/nginx"
NGINX_CONF="/etc/nginx/nginx.conf"
NGINX_PID="/var/run/nginx.pid"
RETVAL=0
prog="Nginx"
 
#Source networking configuration
. /etc/sysconfig/network
# Check networking is up
[ ${NETWORKING} = "no" ] && exit 0
[ -x $NGINX_SBIN ] || exit 0
 
start() {
        echo -n $"Starting $prog: "
        touch /var/lock/subsys/nginx
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}
 
stop() {
        echo -n $"Stopping $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -TERM
        rm -rf /var/lock/subsys/nginx /var/run/nginx.pid
        RETVAL=$?
        echo
        return $RETVAL
}
 
reload(){
        echo -n $"Reloading $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}
 
restart(){
        stop
        start
}
 
configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}
 
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac
 
exit $RETVAL

创建这个目录不然报错,无法启动服务
mkdir -p /tmp/nginx/client_body

赋予nginx脚本权限
chmod -R 777 /etc/init.d/nginx

设置nginx开机启动
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
service nginx stop

防火墙设置通过nginx
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload

查看nginx版本
nginx -v

测试nginx访问
在浏览器输入http://Your-IP/

0 0