【问题标题】:Nginx + Nuxt website not redirecting to 404Nginx + Nuxt 网站未重定向到 404
【发布时间】:2021-03-25 17:30:32
【问题描述】:

我有一个使用 Laravel + Nuxt 开发的网站。我正在使用 Nginx 运行网站。在 nuxt generate + nuxt start 我被重定向到 404 但在实时网站上我正在无限加载:https://flowerqueen.ro/aiusdhiusadfisadiufh。玩了很多配置文件并检查堆栈上的其他答案,没有任何帮助:(

这是我的 nginx 配置:

 map $sent_http_content_type $expires {
               default                       on;
        text/html                  epoch;
        text/css                   max;
        application/javascript     max;
        ~image/                    max;
    }
        
 server {
        # redirect all HTTP to HTTPS
        listen 80;
        expires $expires;
        index index.php index.html;
        server_name flowerqueen.ro www.flowerqueen.ro;
        
        return 301 https://flowerqueen.ro$request_uri;
      }
        
        
server {
        listen 443 ssl;
        
        server_name flowerqueen.ro www.flowerqueen.ro;
        
        #ssl    on;
        ssl_certificate    /etc/ssl/certificate.crt;
        ssl_certificate_key    /etc/ssl/private.key;
        
        index index.php index.html;
        error_page 404 /404.html;
        # expires $expires;
        
        
        
        location / {
        proxy_pass http://localhost:4000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_cache cache;
        proxy_cache_key $host$uri$is_args$args;
        proxy_cache_valid 200 301 302 12h;
        #               try_files $uri $uri/ /404.html;
        #        add_header X-Proxy-Cache $upstream_cache_status;
        }
        location ^~ /images {
        proxy_cache cache;
        proxy_cache_valid 200 301 302 12h;
   }
        
}

努克斯特:

    ssr: true,
    target: 'static',
    server: {
      port: 4000,
      host: 'localhost',
    },

【问题讨论】:

    标签: nginx nuxt.js


    【解决方案1】:

    终于解决了这个问题,谷歌现在会很高兴。 问题出在这里:

      generate: {
         fallback: '404.html',
    

    我在/pages 目录下有页面404.vue,但这不起作用。

    404.vue 更改并移动到404/index.vue 并将配置更改为:

      generate: {
           fallback: '404/index.html',
    

    为我解决了这个问题。

    我还从 404 页面中删除了所有不必要的代码。

    谢谢大家的帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-01
      • 1970-01-01
      • 2020-07-17
      • 2018-09-26
      • 1970-01-01
      • 1970-01-01
      • 2013-06-18
      相关资源
      最近更新 更多