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:
- Verified the dockerized applications work correctly in isolation
- Confirmed the base path
/blog
functions properly - Inspected network requests which suggest this is a client-side routing issue rather than a server-side redirect
- 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.