服务器用nginx部署环境挂载vue项目

所涉及到的环境与工具:

  1. shell
  2. nginx
  3. xftp
  4. linux环境
  5. 服务

服务器使用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  **********;//服务器ip 或者域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root  /home/lzx/dist_text/dist;//vue项目打包的文件路径
            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 关闭开机自动开启
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值