NextJS 应用程序使用 Nginx 反向代理刷新到 PM2

问题描述 投票:0回答:1

我使用 Nginx 和 PM2 在 Debian 12 上运行我的 NextJS 应用程序。我使用 Nginx 作为反向代理,总的来说,它运行良好,我的应用程序运行。

但是我在浏览页面时遇到问题。

无论我使用 router.push('/path/to/route') 还是 next/link 的 Link 组件,url 都会被修改,页面会完全重新加载,而不是平滑导航。

我尝试将 Nginx 配置更改为:

server {
    listen 80;
    listen [::]:80;
    server_name _;
    access_log /var/log/nginx/nextjs_access.log;
    error_log /var/log/nginx/nextjs_error.log error;

    location /_next/ {
        alias /path/to/my/.next/;
        expires 30d;
        access_log on;
    }

    location / {
        # reverse proxy for next server
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        
        proxy_cache_bypass $http_upgrade;
        proxy_pass http://_;
        proxy_redirect off;
        proxy_read_timeout 240s;
    }

并尝试更改 mime.types 文件,就像我在其他站点中看到的那样,以删除 text/x-content 类型,但不起作用。

编辑 28/03:

我通过删除 Nginx 配置的

location /_next/
部分解决了我的问题。 :)

nginx next.js navigation reverse-proxy pm2
1个回答
0
投票

我通过删除 Nginx 配置的 location /_next/ 部分解决了我的问题。 :)

© www.soinside.com 2019 - 2024. All rights reserved.