所涉及到的环境与工具:
- shell
- nginx
- xftp
- linux环境
- 服务
服务器使用nginx部署挂载vue项目
这里vue项目打包命令:npm run build 会生成一个dist文件
一、安装nginx
yum install -y nginx
**注意:**安装成功后:默认的默认的网页路径为:、usr/share/nginx/html 默认的配置文件为/etc/nginx/nginx.conf
二、开启端口80和443
前提:先打开防火墙 systemctl start firewalld service
-
firewall-cmd --reload 重启防火墙 -
firewall-cmd – state 参看防火墙状态 -
systemctl stop firewakkd service 关闭防火墙 -
firewall-cmd --add-port=80/tcp --permanebnt 开启80端口 -
firewall -cmd – permanent --zone = public --add-service=http -
firewall -cmd – permanent --zone = public --add-service=https 开启后记得重启防火墙
三、修改nginx配置文件
前提工作:
在这里我是用linux在服务器下新建自己的目录,利用xftp将打包好的dist文件放在我的目录下面:/home/lzx/dist_text
配置文件修改
输入命令:cd/usr/local/nginx/conf 在该目录下找到nginx.conf
配置文件:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server{
listen 5510;
server_name **********;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/lzx/dist_text/dist;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
修改完毕后ESC :wq保存退出 重启nginx :systemctl restart nginx 一定记得要重启nginx才能生效 然后去浏览器输入自己的ip+端口验证是否成功!
nginx基本命令
- systemctl start nginx 启动
- systemctl restart nginx 重启
- systemctl stio nginx 关闭
- systemctl status nginx 参看状态
- systemctl enable nginx 开启开机自动开启
- systemctl disable nginx 关闭开机自动开启
|