最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

astrojs - Nginx reverse proxy: Subpaths lose prefix (blogposts → posts) when serving Astro.js blog alongside Next.js site - Stac

programmeradmin2浏览0评论

I'm implementing a setup with Next.js and Astro.js behind an Nginx reverse proxy. While the base blog path functions correctly, I'm encountering an issue where subpaths unexpectedly lose their /blog prefix during client-side navigation.

Environment:

  • Next.js main site (Docker container on localhost:3000)
  • Astro.js blog (Docker container on localhost:7000)
  • Nginx reverse proxy with SSL (Certbot)
  • Latest versions of all components

Problem Description: The base URL example/blog works as expected, but when navigating to any subpath, the URL is rewritten incorrectly:

example/blog/posts → example/posts
example/blog/about → example/about

Nginx Configuration:

server {
    server_name example;
    
    location /blog {
        proxy_pass http://localhost:7000/;
        proxy_redirect off;
        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_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_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Port $server_port;
    }

    location / {
        proxy_pass http://localhost:3000/;
        # Similar proxy settings as above
    }
}

Astro Configuration:

export default defineConfig({
  site: ";,
  base: '/blog',
  integrations: [mdx(), sitemap(), tailwind()],
  markdown: {
    rehypePlugins: [sectionize as unknown as [string, any]],
    syntaxHighlight: false, 
  },
  image: {
    domains: ["img.youtube"],
  },
});

What I've Tried:

  1. Verified the dockerized applications work correctly in isolation
  2. Confirmed the base path /blog functions properly
  3. Inspected network requests which suggest this is a client-side routing issue rather than a server-side redirect
  4. Researched similar issues, finding a parallel case with Gatsby (detailed here)

Question: How can I prevent the /blog prefix from being stripped during client-side navigation in Astro.js while maintaining the Nginx reverse proxy setup?

Additional Context: Both applications are properly dockerized and the base routing works correctly, suggesting this is specifically a path-handling issue during client-side navigation. Network inspection shows no server-side redirects occurring.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论