linux 部署 vue-admin-element 项目

部署 vue-admin-element

  • 在vue.config.js中更改 将 publicPath :'/' 更改为 publicPath :'./'

  • 使用打包命令 npm run build:prod

  • 将生成的 dist 文件夹 上传到 服务器 /home

  • 配置 nginx.conf

     server {
            listen       80;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
     
            location / {
                root   /home;
                index  index.html index.htm;
                autoindex on;
                autoindex_exact_size on;
                autoindex_localtime on;
            }
            
            location /fishapi {
                proxy_set_header Host                    $host;
                proxy_set_header x-forwarded-for         $remote_addr;
                proxy_set_header X-Real-IP               $remote_addr;
                proxy_pass                               http://127.0.0.1:8000;
             }
             
            add_header Access-Control-Allow-Origin "*";
            default_type 'text/html';
            charset utf-8;
            #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;
            }
     }
    
  • 浏览器可以直接访问 http://x.x.x.x/dist

原文地址:https://www.cnblogs.com/wuxiaoshi/p/13600886.html