第二步:安装nginx
这里使用OpenResty(一个通过扩展 Nginx 实现的高性能Web服务器,使用Nginx+Lua的方式,对于高并发网站开发非常有用)
安装
(1)进入官方网站http://openresty.org/cn/找到下载地址如https://openresty.org/download/ngx_openresty-1.9.3.1.tar.gz
(2) 在 /opt 目录下通过wget下载
wget https://openresty.org/download/ngx_openresty-1.9.3.1.tar.gz
(3)解压
tar xvf ngx_openresty-1.9.3.1.tar.gz
(4) 移动目录
mv ngx_openresty-1.9.3.1 nginxopen
(5) 安装以下的开发库
apt-get install libreadline-dev libpcre3-dev libssl-dev perl
(6)进入nginxopen目录,依次执行以下命令,安装完成
./configure --prefix=/opt/nginx/
make
make install
设置开机启动
(1) 安装服务管理
sudo apt-get install sysv-rc-conf
(2)创建自启动脚本
-
在/etc/init.d/目录下创建nginx
sudo vi /etc/init.d/nginx
并加入内容
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/opt/nginx/nginx/sbin/$NAME
CONFIGFILE=/opt/nginx/nginx/conf/$NAME.conf
PIDFILE=/opt/nginx/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}
do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
(3) 设置开机启动
sudo sysv-rc-conf nginx on
手动重启,停止命令
sudo /etc/init.d/nginx restart
sudo /etc/init.d/nginx stop
*安装成功后的一些文件存放位置
*nginx path prefix: “/opt/nginx//nginx”
nginx configuration prefix: “/opt/nginx//nginx/conf”
nginx pid file: “/opt/nginx//nginx/logs/nginx.pid”
nginx error log file: “/opt/nginx//nginx/logs/error.log”
nginx http access log file: “/opt/nginx//nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
nginx http scgi temporary files: “scgi_temp”*