解决nuxt.js部署nginx代理后,出现闪首页的问题

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

进入nginx配置文件目录

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

创建配置文件

touch nuxt.conf 

写入配置

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
    }
}

重启nginx

nginx -s reload

猜你喜欢

转载自blog.csdn.net/a0405221/article/details/107962035