您的位置:首页 > 运维架构 > Nginx

Ubuntu配置negix并开机自启动

2017-06-03 17:14 246 查看
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 检查是否安装好

cd /usr/local/nginx/sbin/

./nginx

使用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=0
prog="nginx"

#Check that networking is up
[ -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: "
$nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ]
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
$nginxd -s stop
RETVAL=$?
echo
[ $RETVAL = 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 1
esac
exit $RETVAL


3.2 设置文件的访问权限

chmod a+x /etc/init.d/nginx

这样在控制台就好操作Nginx了如下:



3.3 开机自启动

vi /etc/rc.local

加入一行 /etc/init.d/nginx start 保存并退出,下次重启会生效。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx ubuntu