#Nginx does not serve 404 with static server

4 messages · Page 1 of 1 (latest)

flat lintel
#

Hello!

So my issue is that the 404 from astro is not served by Nginx with the following configuration:

        location /my-thing {
                proxy_pass http://127.0.0.1:4666/my-thing;
                proxy_http_version 1.1;
                proxy_pass_header Server;

                error_page 404 @thing_404;

                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                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_cache_bypass $http_upgrade;
        }

        location @thing_404 {
                return 302 https://fullurltosomething/;
        }

In the example above, https://fullurltosomething/ never fires off. I still get a 404 error, but even though I am running an astro preview on http://127.0.0.1:4666/my-thing with a 404.astro file, I don't get to see it. It works without Nginx (getting served the actual 404.astro file). Any ideas how to make this work? Thanks!

PS. I suspect it has to do with astro preview's behavior because the same pattern works for something else i.e nextjs.

hot sandal
#

Is your site fully static or server/hybrid? You shouldn't be using astro preview in production to serve your site, that might be the issue

flat lintel
# hot sandal Is your site fully static or server/hybrid? You shouldn't be using `astro previe...

Hey, yeah my astro config looks like this:

import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import mdx from "@astrojs/mdx";
import react from "@astrojs/react";
import sitemap from "@astrojs/sitemap";
import compress from "astro-compress";
import tailwindcssNesting from "tailwindcss/nesting";

// https://astro.build/config
export default defineConfig({
  output: "static",

  server: {
    port: 4666,
  },

  integrations: [
    sitemap(),
    react(),
    tailwind({
      applyBaseStyles: false,
    }),
    mdx(),
    compress(),
  ],
  vite: {
    css: {
      postcss: {
        plugins: [tailwindcssNesting()],
      },
    },
  },
});
flat lintel