使用Nginx将项目部署在本地

94 阅读1分钟
  1. 在项目终端里运行npm run build打包项目生成dist文件并放到Nginx的html文件夹下。

  2. 打开conf文件夹下的nginx.conf进行配置vue3

    history路由打包的nginx.conf配置(在一级目录下配置):

     server {
        listen 8001;
        server_name  localhost;
        location / {
          root E:/nginx/nginx-1.26.3/html/dist;
          index index.html;
          try_files $uri $uri/ /index.html;//解决刷新页面404的问题
        }}
    

    hash路由打包的nginx.conf配置(在一级目录下配置):

    hash路由打包没有刷新页面404的问题。

    server {
        listen 8001;
        server_name localhost;
        location / {
          root E:/nginx/nginx-1.26.3/html/dist;
      }}
    

    hash路由打包的nginx.conf配置(在二级目录下配置):

    此时需要在项目的vue.config.js中配置 base:'./' (vite构建的项目中), 或 publicPath:'./' (webpack构建的项目中) 参考文档blog.csdn.net/weixin_5195…

    server {
        listen 8001;
        server_name localhost;
        location  /dist {
          root E:/Web/vue3-vite-project;
      }}
    

vue2老版(vue init)打包后404以及ElementUI打包后图标不显示问题

blog.csdn.net/progrmmmm/a…