Vue history mode deployment to Nginx refresh 404

the project is deployed on Nginx. Because the / change directory has already given other permissions, it is said that the project is directly placed under / dist, so the assetsPublicPath changes to the relative path

when build.
build: {
    // Template for index.html
    index: path.resolve(__dirname, "../dist/index.html"),

    // Paths
    assetsRoot: path.resolve(__dirname, "../dist"),
    assetsSubDirectory: "static",
    assetsPublicPath: "./",
When

build, the API also requests the root path directly. It"s no problem

const service = axios.create({
  //baseURL: process.env.ENV_CONFIG=="dev"?"/api":"", // apibase_url
  baseURL: process.env.ENV_CONFIG=="dev"?"/api":process.env.BASE_API,
  timeout: 5000, // 
  headers:{
    "isWeb": 1,
    "Content-Type": "application/json;charset=utf-8"
  }
})

but according to the official statement, as Nginx said, the configuration https://blog.csdn.net/u011025., refresh or error 404, then I searched and said that assetsPublicPath may be configured as an absolute path, but if configured as an absolute path, static resources cannot be found

.

clipboard.png
ask for answers


ide/essentials/history-mode.html-sharp%E5%90%8E%E7%AB%AF%E9%85%8D%E7%BD%AE%E4%BE%8B%E5%AD%90" rel=" nofollow noreferrer "> https://router.vuejs.org/zh/g.

server {
    listen 80 default_server;
    server_name /var/www/example.com;

    root /var/www/example.com;
    index index.html index.htm;      

    location ~* \.(?:manifest|appcache|html?|xml|json)$ {
      expires -1;
      -sharp access_log logs/static.log; -sharp I don't usually include a static log
    }

    location ~* \.(?:css|js)$ {
      try_files $uri =404;
      expires 1y;
      access_log off;
      add_header Cache-Control "public";
    }

    -sharp Any route containing a file extension (e.g. /devicesfile.js)
    location ~ ^.+\..+$ {
      try_files $uri =404;
    }

    -sharp Any route that doesn't have a file extension (e.g. /devices)
    location / {
        try_files $uri $uri/ /index.html;
    }
}

The

problem is also solved. Thank you. The / dist directory is missing in Nginx configuration.
location / {

        root   dist;
        index  index.html;
        try_files $uri $uri/ /dist/index.html;
    }
Menu