Centos 7 安装Nginx、设置为自启动服务、部署vue静态打包文件笔记

A.vue项目打包
npm run build
B.Centos 7.0 安装nginx
1.依赖安装
yum install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
2.Nginx安装
cd /usr/local
wget http://nginx.org/download/nginx-1.13.6.tar.gz
tar -zvxf nginx-1.13.6.tar.gz
cd nginx-1.13.6
./configure --with-http_ssl_module --with-http_gzip_static_module
make && make install

 配置信息查看

程序位置:/usr/local/nginx/sbin/nginx
配置文件位置:/usr/local/nginx/conf/nginx.conf
查看运行进程状态:
ps aux | grep nginx

停止nginx:
./nginx -s stop

重启nginx(配置文件变动后需要重启才能生效):
./nginx -s reload

检查配置文件是否正确:
./nginx -t

查看nginx的pid:
cat /usr/local/nginx/logs/nginx.pid

查看nginx版本

./nginx -v

回头看编译配置
./nginx -V


C.设置nginx为系统服务

1.添加系统配置文件
vi /etc/init.d/nginx
添加如下内容
#! /bin/bash
# chkconfig: 2345 10 90
#StartupscriptforthenginxWebServer
#description:nginxisaWorldWideWebserver.Itisusedtoserve
#HTMLfilesandCGI.
#processname:nginx
#pidfile:/usr/local/nginx/logs/nginx.pid
#config:/usr/local/nginx/conf/nginx.conf
PATH=/usr/local/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/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() {
$DAEMON -s stop || echo -n "nginx not running"
}
do_reload() {
$DAEMON -s reload || 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

2.设置执行权限
chmod a+x /etc/init.d/nginx
3.注册成服务
chkconfig --add nginx
4.设置开机启动
chkconfig nginx on

对nginx服务执行停止/启动/重新读取配置文件操作
#启动nginx服务
systemctl start nginx.service
#停止nginx服务
systemctl stop nginx.service
#重启nginx服务
systemctl restart nginx.service
#重新读取nginx配置(这个最常用, 不用停止nginx服务就能使修改的配置生效)
systemctl reload nginx.service

D 发布静态资源html
1.将打包好的vue项目放到 /usr/local/webSpace/目录下

2.修改nginx配置文件
vi /usr/local/nginx/conf/nginx.conf
将 server-location-root- 修改为
/usr/local/webSpace/showTime/
3.重新加载nginx
systemctl reload nginx.service
大功告成

猜你喜欢

转载自blog.csdn.net/linyifan_/article/details/86298201