前面讲到nginx已经安装完成,接下来就是将服务启动起来。
第一种是手动启动,首先找一下nginx,找到就可以写一个命令了
#查找nginx
whereis nginx
#手动启动(启动代码格式:nginx安装目录地址 -c nginx配置文件地址)
/usr/sbin/nginx -c /etc/nginx/nginx.conf
#验证启动
http://IP
第二种是服务器自动启动,首先创建一个脚本文件
vi /etc/init.d/nginx
#按i进入编辑状态,复制粘贴,wq保存
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
killall -9 nginx
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
#赋予脚本执行权限
chmod +x /etc/init.d/nginx
#添加nginx服务进程用户
groupadd -r nginx
useradd -r -g nginx nginx
#添加至服务管理列表,设置开机自启
chkconfig --add nginx
chkconfig nginx on
#在这里踩坑开始,出现错误“No module named 'gdbm'”或“No module named '_gdbm'”,于是离线下载了gdbm-1.12.tar.gz
下载地址找到有以下2个,都可以下载:
https://ftp.gnu.org/gnu/gdbm/
http://mirrors.nju.edu.cn/gnu/gdbm/
#解压
tar -zxvf gdbm-1.12.tar.gz
#进入目录
cd gdbm-1.12
#创建安装目录
mkdir /usr/local/gdbm-1.12
#选择安装目录
./configure --enable-memory-mapped-io --prefix=/usr/local/gdbm-1.12 --enable-libgdbm-compat --enable-gdbm-export --with-gdbm183-library=/usr/lib/libgdbm.a --with-gdbm183-libdir=/usr/local/lib --with-gdbm183-includedir=/usr/local/include
#编译
make
#出现错误“gcc: error: /usr/lib/libgdbm.a: No such file or directory”,不管它,继续安装,装好后去“/usr/local/gdbm-1.12/lib/”目录下把的“libgdbm.a”手动复制到“/usr/lib”目录
make install
?#然后回到“gdbm-1.12”目录,清除编译缓存
make clean
?#再次选择安装目录
./configure --enable-memory-mapped-io --prefix=/usr/local/gdbm-1.12 --enable-libgdbm-compat --enable-gdbm-export --with-gdbm183-library=/usr/lib/libgdbm.a --with-gdbm183-libdir=/usr/local/lib --with-gdbm183-includedir=/usr/local/include
#编译
make
#安装,此时gdbm已安装完成
make install
#重新添加至服务管理列表,设置开机自启
chkconfig --add nginx
chkconfig nginx on
#关闭防火墙
systemctl stop firewalld
?#开启Nginx服务
service nginx start
#验证启动成功 浏览器访问:http://IP
参考:
linux下nginx部署以及配置详解 - 韦邦杠 - 博客园
gdbm编译安装及问题解决_zhu_1211的专栏-CSDN博客_gdbm安装
qconf安装过程遇到的问题及解决方案_yinn-CSDN博客
|