当前位置:   article > 正文

解决nuxt.js部署nginx代理后,出现闪首页的问题_nginx代理导致访问时地址栏一直闪烁

nginx代理导致访问时地址栏一直闪烁

用这份配置之前,用了官方提供的 try_files $uri $uri/ /;,出现了一个致命问题,就是非当前页(跳新标签)与刷新页面时,会先跳首页,再出现对应页面
用于nuxtjs 启动项目,使用nginx反向代理至80端口

进入nginx配置文件目录

cd /usr/local/nginx/conf/conf.d
  • 1

创建配置文件

touch nuxt.conf 
  • 1

写入配置

map $sent_http_content_type $expires {
    "text/html"                 epoch;
    "text/html; charset=utf-8"  epoch;
    default                     off;
}

server {
    listen          80;             # the port nginx is listening on
    server_name     localhost;    # setup your domain here

    gzip            on;
    gzip_types      text/plain application/xml text/css application/javascript;
    gzip_min_length 1000;

    location / {
        expires $expires;

        proxy_redirect                      off;
        proxy_set_header Host               $host;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_read_timeout          1m;
        proxy_connect_timeout       1m;
        proxy_pass                          http://127.0.0.1:3001; # set the address of the Node.js instance here
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

重启nginx

nginx -s reload
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/592928
推荐阅读
相关标签
  

闽ICP备14008679号