Return proper status codes (404, 302) from client-side Single Page Application

msonntag nginx-forum at
Mon Aug 8 09:50:54 UTC 2016


I have the following scenario:

- Client: AngularJS-based SPA running on
- Backend: API running on

Both live in one nginx instance in two separate "server" environments.

- Browsing to launches the Angular app
- App sends request to
- If item 1 does not exist, API returns 404 status code
- Client app can now show soft 404 error page, all fine
- But for crawlers/search engines, I want to return a proper HTTP status
code. Same goes for redirect to item’s canonical URL if that is necessary.

So my idea was to do sth like this:

- If request URL matches<id>, check existence of item
by sending a HEAD request to<id>
- If request returns 404, return proper status code and error page
- If request returns 200, do nothing and just serve the Angular app

Is there any way to do this with (plain) nginx and if so–how could it be
done specifically?

Thanks for any hints :)

Posted at Nginx Forum:,268827,268827#msg-268827

More information about the nginx mailing list