1. Nginx安装环境
- gcc
- pcre库
- zlib库
- openssl库
安装方式网上有
2.编译安装
网上下载Nginx-1.8.0.tar.gz,并拷贝到Ubuntu
2.1 解压:tar -zxvf Nginx-1.8.0.tar.gz
2.2 进入文件夹:cd Nginx-1.8.0
2.3 配置
命令行输入:
./configure \
然后将如下命令拷入命令行
--prefix=/usr/local/Nginx \ --pid-path=/var/run/Nginx/Nginx.pid \ --lock-path=/var/lock/Nginx.lock \ --error-log-path=/var/log/Nginx/error.log \ --http-log-path=/var/log/Nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/Nginx/client \ --http-proxy-temp-path=/var/temp/Nginx/proxy \ --http-fastcgi-temp-path=/var/temp/Nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/Nginx/uwsgi \ --http-scgi-temp-path=/var/temp/Nginx/scgi
2.4 部分文件夹建立
因为以上临时文件指定目录在var/temp/Nginx
所以要在var文件夹建立/temp/Nginx文件夹。使用mkdir xx
2.5 编译安装
make
make install
无错才可以进行下一步
2.6 检查是否安装好
使用ps指令看是否启动成功
ps aux|grep Nginx
在Ubuntu浏览器下输入localhost/ ,有如下表示安装配置成功
3 开机自启动
为了方便使用Nginx服务器,可以进行Ubuntu开机自启动。
3.1 编写处理脚本、
vim /etc/init.d/Nginx
复制如下内容
#nx 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=/usr/local/Nginx/sbin/Nginx
Nginx_config=/usr/local/Nginx/conf/Nginx.conf
Nginx_pid=/var/run/Nginx.pid
RETVAL=@H_301_155@0
prog="Nginx"
#Check that networking is up
[ -x $Nginxd ] || exit @H_301_155@0
## Start Nginx daemons functions.
start() {
if [ -e $Nginx_pid ];then
echo "Nginx already running...."
exit @H_301_155@1
fi
echo -n $"Starting $prog: "
$Nginxd -c ${Nginx_config}
RETVAL=$?
echo
[ $RETVAL = @H_301_155@0 ]
return $RETVAL
}
# Stop Nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
$Nginxd -s stop
RETVAL=$?
echo
[ $RETVAL = @H_301_155@0 ] && rm -f /var/lock/subsys/Nginx $Nginx_pid
}
# reload Nginx service functions.
reload() {
echo -n $"Reloading $prog: "
kill -HUP `cat ${Nginx_pid}`
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 @H_301_155@1
esac
exit $RETVAL
3.2 设置文件的访问权限
chmod a+x /etc/init.d/Nginx
这样在控制台就好操作Nginx了如下:
3.3 开机自启动
原文链接:https://www.f2er.com/ubuntu/352750.htmlvi /etc/rc.local