zoukankan      html  css  js  c++  java
  • vue部署问题

    history模式配置后刷新404的解决办法!

    第一种 nginx配置     

    在usr/local/nginx/conf/vhost 下 域名.conf配置文件修改或添加

    
    
    第一种方案

    server
        {
            ##在server下添加或在location里面添加以下代码
            location / 
            {
                if (!-e $request_filename) {
                    rewrite ^(.*)$ /index.html?s=$1 last;
                    break;
                }
            }
            ## 如果访问的不是根目录用下面方式设置 qiancheng是我的子目录
            location /qiancheng{
                if (!-e $request_filename) {
                    rewrite ^/(.*) /qiancheng/index.html last;
                    break;
                }
            }
        }
    第二种方案
    location / { try_files $uri $uri/ /index.html; }
     

    第二种  Apache

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index.html$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.html [L]
    </IfModule>

    第三种 原生 Node.js

    const http = require('http')
    const fs = require('fs')
    const httpPort = 80
    
    http.createServer((req, res) => {
      fs.readFile('index.htm', 'utf-8', (err, content) => {
        if (err) {
          console.log('We cannot open "index.htm" file.')
        }
    
        res.writeHead(200, {
          'Content-Type': 'text/html; charset=utf-8'
        })
    
        res.end(content)
      })
    }).listen(httpPort, () => {
      console.log('Server listening on: http://localhost:%s', httpPort)
    })

    第四种  Firebase 主机

    在你的 firebase.json 中加入:
    {
      "hosting": {
        "public": "dist",
        "rewrites": [
          {
            "source": "**",
            "destination": "/index.html"
          }
        ]
      }
    }

    第五种 tomcat的配置

    添加 WEB-INF文件夹web.xml文件 加入下列代码:

    <web-app>
      <error-page>
        <error-code>404</error-code>
        <location>/index.html</location>
      </error-page>
    </web-app>

    参考文件

    https://router.vuejs.org/zh/guide/essentials/history-mode.html#%E5%90%8E%E7%AB%AF%E9%85%8D%E7%BD%AE%E4%BE%8B%E5%AD%90

  • 相关阅读:
    jwt手动生成access_token
    python学习-52 XML模块
    python学习-51 shelve模块
    python学习-50 pickle模块
    python学习-49 json模块
    python学习-48 模块2
    python学习-47 random模块
    python学习-46 时间模块
    python学习-45 模块
    python学习-44 程序的解耦 (不是特别懂的,回头在复习)
  • 原文地址:https://www.cnblogs.com/miaoyiyan/p/9635566.html
Copyright © 2011-2022 走看看