Centos 6.5 Nginx 快速部署
2016-05-29 20:35
543 查看
依赖包安装
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/
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/
相关文章推荐
- codeigniter nginx rewrite规则配置【转】
- nginx基本配置与参数说明
- Nginx 主配置文件参数详解
- Ubuntu14+Nginx安装配置(edusoho)
- nginx作为负载均衡服务器——测试
- Nginx负载均衡配置实例详解
- (在线文库系统)centos+nginx+mysql+php+openoffice+pdf2swf+pdf2image
- nginx笔记
- Nginx中运行403 forbidden错误
- Unix 系统下的 Nginx 1.4.x
- Nginx负载均衡配置
- nginx集群报错“upstream”directive is not allow here 错误
- Nginx事件管理机制-epoll
- CentOS源码安装搭建LNMP全过程(包括nginx,mysql,php,svn)【转】
- nginx-systemtap-toolkit
- nginx配置location总结及rewrite规则写法
- Installing optional Nginx modules with apt-get nginx_uploadprogress_module
- nginx虚拟主机配置小结
- nginx 编译安装时提示md5.h不存在
- nginx启动脚本和配置文件