Search code examples
nginxnext.jsnavigationreverse-proxypm2

NextJS app refreshing with Nginx reverse proxy to PM2


I'm using Nginx and PM2 to run my NextJS application on Debian 12. I'm using Nginx as a reverse proxy and, on the whole, it works well, my application runs.

But I'm having a problem browsing pages.

Whether I use router.push('/path/to/route') or a Link component of next/link, the url is modified and the page completely reloaded instead of a smooth navigation.

I tried to change the Nginx configuration, to this :

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

And tried to change the mime.types file like i see in other site to remove the text/x-content type but not working.

EDIT 28/03:

I've fixed my issue by deleting location /_next/ section of my Nginx configuration. :)


Solution

  • I've fixed my issue by deleting location /_next/ section of my Nginx configuration. :)