vue项目部署nginx

  • 打包

        首先咱们使用 npm run build 来生成项目的静态页面,会在项目的根路径的dist目录下php

咱们将dist下的 index.htmlstatic静态文件发布到服务器的某一目录下css

  • nginx配置

      nginx安装完成,修改conf/nginx.conf文件, server  节点下 listen 修改监听端口, 添加子配置文件 include vhost/*.conf;  html

vue.conf文件内容前端

server {
    listen                      7001; 
    server_name                 localhost;
    root                        /usr/local/edu-cloud/edu-vue;

    location / { 
        index   index.html index.php;
    }   

    # 媒体资源文件
    # TODO: 用一个static.hostmanager.com 之类的域名放置
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
         expires      30d;
    }   

    # 前端代码
    # TODO: 用一个fe.hostmanager.com之类的域名放置
    location ~ .*.(js|css)$ {
         expires      1h; 
    }   
}

重启nginx ,nginx -s reloadvue