Discussion:
nginx: turn a 404 into a 302 found?
(too old to reply)
Eli the Bearded
2018-08-14 18:45:23 UTC
Permalink
I've done most of work with websevers using Apache. I'm trying to learn
the ways of Nginx for comparison. The pieces certainly fit together
differently with Nginx.

Here's a rough overview of what I have:

* main page of the site is a CGI using fastcgi
* this page mostly just issues redirects (302)
for the purposes of discussion, the redirect issued can be
considered random and constantly different (hence need for CGI)
(in actuality, it's deterministic)
* when someone requests a file besides the main page, if it
exists, I want people to reach it
* when someone requests a file that is a 404, I want the main
page CGI to run, so I added to the conf:
error_page 404 /index.cgi;

That all works. But the main page issues a "Status: 302" and a
"Location:" header, yet clients requesting a bad URL never see
a "HTTP/1.1 302 Found" response, instead they get a "HTTP/1.1 404
Not Found" which includes a "Location" header.

So is this something I fix in Nginx? Fastcgi? My CGI script? What's the
trick for converting the 404 to a new status?

Elijah
------
not sure where to begin searching for that
Eli the Bearded
2018-08-15 19:11:34 UTC
Permalink
In comp.infosystems.www.servers.unix,
Post by Eli the Bearded
* main page of the site is a CGI using fastcgi
* this page mostly just issues redirects (302)
for the purposes of discussion, the redirect issued can be
considered random and constantly different (hence need for CGI)
(in actuality, it's deterministic)
* when someone requests a file besides the main page, if it
exists, I want people to reach it
* when someone requests a file that is a 404, I want the main
error_page 404 /index.cgi;
That all works. But the main page issues a "Status: 302" and a
"Location:" header, yet clients requesting a bad URL never see
a "HTTP/1.1 302 Found" response, instead they get a "HTTP/1.1 404
Not Found" which includes a "Location" header.
So is this something I fix in Nginx? Fastcgi? My CGI script? What's the
trick for converting the 404 to a new status?
I've been able to get it working a little better by using a double
redirect. All 404s get a fixed redirect to the mainpage and then the CGI
runs and gives the second redirect. Still not ideal, but better.

Elijah
------
expects most 404s to come from people nosing about

Loading...