鍍金池/ 問答/PHP  網(wǎng)絡(luò)安全  網(wǎng)絡(luò)營銷  HTML/ vue spa項目,history模式,微信分享時,安卓微信瀏覽器顯示404

vue spa項目,history模式,微信分享時,安卓微信瀏覽器顯示404

vue spa項目,history模式,https://news.otimes.com/list/... 這種帶參數(shù)的鏈接,安卓微信瀏覽器顯示404,https://news.otimes.com 不帶參數(shù)的鏈接能顯示,跳轉(zhuǎn)也是正常的,是不是安卓瀏覽器不能兼容history模式,我可以怎么改嗎?

前端配置了

 {
      path: '*',
      name: 'notFind',
      meta: {
        title: '404未找到',
      },
      components: setLogoComponents(notFind)
    },

后臺是tomcat,也配置了

 <error-page>  
   <error-code>404</error-code>  
   <location>/</location>  
</error-page> 

火狐,谷歌,ie下都沒有404,微信開發(fā)工具雖然也有404,但還是能訪問,只有安卓微信瀏覽器,404

ps:https證書已布上,也是已備案的域名,微信js安全域名和白名單都已配置

1.chrome模擬器,能訪問,無404,
圖片描述

2.微信開發(fā)者工具,能訪問,有404
圖片描述

3.安卓手機微信瀏覽器,不能訪問,有404
圖片描述

回答
編輯回答
影魅

感謝這位大神,寫的都很清楚了,http://blog.csdn.net/xu122723...。

問題的主要原因是,雖然tomcat已經(jīng)攔截了404,并指向了我的index頁面,但是這個404的標記還是存在,只要遇見存在404錯誤頁處理的平臺,就gg了。就比如微信平臺,他檢測到你的404,就立馬跳向公益404頁面了。

解決方法一:后臺設(shè)置攔截器,在發(fā)送任何請求前,后臺都做攔截,并指向index頁面。

解決方法二:用nginx進行攔截,修改nginx.conf文件

http {

# 此處省略好多字

server {

    # nginx才配使用80端口,其他服務(wù)速速離去
    listen       80;

    # 沒啥好解釋的
    server_name  localhost;

    # 指定根目錄,由于我的前端項目是直接放在nginx下的html文件夾,所以我這樣配
    root html;

    # 這里其實是由if變過來的,意思是如果uri存在,那就訪問uri的資源,如果uri不存在,那就訪問該目錄下index.html文件。如果看不懂我的解釋,可以看這個https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#front-controller-pattern-web-apps
    try_files $uri $uri/ /index.html;

    # 這里是配你Tomcat里面的其他java項目,意思是當你訪問http://ip/xxx的時候,會到這個代碼塊里面進行對應(yīng)操作
    location /xxx {
        # 這些照著加就好了,無非是獲取服務(wù)器host/ip相關(guān),一定要加,否則如果你的項目并不是前后端分離,而是SSH/SSM帶有jsp或者模板頁面的,那就會出現(xiàn)找不到css/js等找不到一切靜態(tài)資源文件的錯誤。為什么會報錯,因為你看network面板你就知道,他是去訪問http://127.0.0.1/xxx/css...而并不是訪問服務(wù)器的真實ip,所以還是乖乖加上吧!
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # 去該地址去找項目資源
        proxy_pass http://127.0.0.1:8080/xxx;
    }
  }
}
2018年9月20日 15:50
編輯回答
刮刮樂
upstream ups_ucar_wx {
  #ip_hash;
  #consistent_hash $remote_addr;
  server 192.168.8.59:8080;
  #check interval=10000 rise=2 fall=5 timeout=1000 type=http default_down=false;
  #check_http_send "GET /health HTTP/1.0\r\n\r\n";
}

server {
  listen      80;
  server_name   xxx.com;
  charset     utf-8;
  access_log  logs/xxx.access.log  main;
  error_log   logs/xxx.error.log;
  
  #include /etc/nginx/agent_deny.conf;

  location / {
    proxy_pass  http://ups_ucar_wx;
    # 具體做什么,不懂,不過不加會顯示400
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # 匹配不到的路徑,都跳/index.html
    try_files $uri $uri/ /index.html;
  }

  location /static/ {
    root /;
    proxy_pass  http://ups_ucar_wx;
    # 具體做什么,不懂,不過不加會顯示400
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # 設(shè)置過期時間
    expires 30d;
  }
}

https://www.jianshu.com/p/47e...

2018年6月1日 22:57