Eugene Krakos
Eugene Krakos

Reputation: 159

Nginx config for 404.html

I have the following problem. I have angular 2 app, which is store at the same server as backend. I have api through /api route, also I have /apidoc route. I have the following nginx config to get history api working for angular 2 app:

location / {
    try_files $uri/index.html $uri.html $uri @app;
    gzip_static on;

    rewrite “^/faq” /index.html last;
    rewrite “^/support” /index.html last;
    rewrite “^/issue/*” /index.html last;
    rewrite “^/settings” /index.html last;
    rewrite “^/reset” /index.html last;
    rewrite “^/confirm” /index.html last;
    rewrite “^/terms” /index.html last;
}

I need all routes (excluding /api/* , /apidoc and mentioned above in config) redirected to 404.html. What I need to write in config to achieve this?

Upvotes: 1

Views: 367

Answers (1)

Dmitry Krakosevich
Dmitry Krakosevich

Reputation: 305

Try adding this code below your location:

location ~ ^(?!\/(404|index|api|apidoc|faq|support|issue|settings|reset|confirm|terms)\b).* {
    error_page 404 /404.html;
}

It may work

Upvotes: 1

Related Questions