zoukankan      html  css  js  c++  java
  • nginx+vue刷新404

    问题原因:
    刷新页面时访问的资源在服务端找不到,因为vue-router设置的路径不是真实存在的路径。
    如上的404现象,是因为在nginx配置的根目录/Data/app/xqsj_wx/dist下面压根没有loading这个真实资源存在,这些访问资源都是在js里渲染的。

    服务端nginx的一开始配置如下(假设域名为:testwx.wangshibo.com):
    [root@test-huanqiu ~]# cat /Data/app/nginx/conf/vhosts/testwx.wangshibo.com.conf 
             server {
             listen 80;

             server_name testwx.wangshibo.com;
             root /Data/app/xqsj_wx/dist;
             index index.html;

             access_log /var/log/testwx.log main;

    }

    如上出现404的原因是由于在这个域名根目录/Data/app/xqsj_wx/dist下面压根就没有loading这个真实目录存在。

    问题解决:
    在nginx配置里添加vue-route的跳转设置(这里首页是index.html,如果是index.php就在下面对应位置替换),正确配置如下(添加下面标红内容):
    [root@test-huanqiu ~]# cat /Data/app/nginx/conf/vhosts/testwx.wangshibo.com.conf 
             server {
             listen 80;

             server_name testwx.wangshibo.com;
             root /Data/app/xqsj_wx/dist;
             index index.html;

             access_log /var/log/testwx.log main;

             location / {
                 try_files $uri $uri/ @router;
                 index index.html;
             }

            location @router {
                rewrite ^.*$ /index.html last;
            }

    }

    重启nginx后,问题就迎刃而解了。

  • 相关阅读:
    ZOJ Problem Set–2417 Lowest Bit
    ZOJ Problem Set–1402 Magnificent Meatballs
    ZOJ Problem Set–1292 Integer Inquiry
    ZOJ Problem Set–1109 Language of FatMouse
    ZOJ Problem Set–1295 Reverse Text
    ZOJ Problem Set–1712 Skew Binary
    ZOJ Problem Set–1151 Word Reversal
    ZOJ Problem Set–1494 Climbing Worm
    ZOJ Problem Set–1251 Box of Bricks
    ZOJ Problem Set–1205 Martian Addition
  • 原文地址:https://www.cnblogs.com/daysn/p/10298113.html
Copyright © 2011-2022 走看看