Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add 5xx error page #3883

Closed
wants to merge 14 commits into from
Closed

feat: add 5xx error page #3883

wants to merge 14 commits into from

Conversation

starsz
Copy link
Contributor

@starsz starsz commented Mar 23, 2021

What this PR does / why we need it:

Show our own HTML page, when the apisix self returns 5xx.
fix #3251

Pre-submission checklist:

  • Did you explain what problem does this PR solves? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@starsz starsz marked this pull request as ready for review March 24, 2021 01:07
@starsz starsz requested review from spacewander and membphis and removed request for spacewander March 24, 2021 01:50
t/cli/test_error_page.sh Outdated Show resolved Hide resolved
apisix/error_handler.lua Outdated Show resolved Hide resolved
. ./t/cli/common.sh

git checkout conf/config.yaml
make init
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need it if we call make run later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@membphis
Copy link
Member

you can merge the master branch

t/cli/test_error_page.sh Outdated Show resolved Hide resolved
echo "failed: the error page is not customized"
exit 1
fi
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add some test cases that an upstream returns 5xx but these error pages are not shown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@membphis
Copy link
Member

ci failed now

@@ -233,6 +233,9 @@ http {
{% end %}
{% end %}

# error_page
error_page 500 502 503 504 @apisix_error_handler;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the 4xx response codes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we do need it.

<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>openresty</center>
</body>
</html>

Maybe we can add a link in the response first.

apisix/error_handler.lua Outdated Show resolved Hide resolved
<p>If you are the system administrator of this resource then you should check
the <a href="https://github.com/apache/apisix/blob/master/conf/config-default.yaml#L135">error log
</a> for details.</p>
<p>If you need any help, click <a href="https://apisix.apache.org/">need help</a>.</em></p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this link can help users

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

https://apisix.apache.org/help/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same to #3883 (comment)

@tokers
Copy link
Contributor

tokers commented Mar 31, 2021

ci failed now

Please fix it when you have time @starsz .

@starsz
Copy link
Contributor Author

starsz commented Mar 31, 2021

ci failed now

Please fix it when you have time @starsz .

Need some time.A little busy lately.

@moonming
Copy link
Member

moonming commented Apr 1, 2021 via email

@@ -50,5 +50,4 @@ return function()
if ngx.status >= 500 and ngx.status <= 599 then
ngx.say(html_5xx)
end
end

end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check your editor, end of line symbol is required.

apisix/error_handler.lua Outdated Show resolved Hide resolved
@moonming
Copy link
Member

moonming commented Apr 4, 2021

ping @starsz

sleep 0.1

# set route
code=$(curl -XPUT -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -d '{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused why you don't test them by Test::Nginx.

@moonming
Copy link
Member

ping @starsz

I am going to close this pr, there is no feedback for too long

@starsz
Copy link
Contributor Author

starsz commented Apr 17, 2021

ping @starsz

I am going to close this pr, there is no feedback for too long

Better not, I will finish it this weekend.

Comment on lines +54 to +61
local ngx_status_line = {
[400] = "400 Bad Request",
[401] = "401 Unauthorized",
[403] = "403 Forbidden",
[404] = "404 Not Found",
[405] = "405 Not Allowed",
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we should add it into 4xx html.
I can't find any API that contains this info.
@tokers @spacewander Do you have any opinions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show status code in body is useful in the browser, I think we can reserve it.

Comment on lines 196 to 214
=== TEST 12: test apisix with upstream error code 400
--- request
GET /specific_status
--- more_headers
X-Test-Upstream-Status: 400
--- error_code: 400
--- response_body
upstream status: 400



=== TEST 11: test apisix with upstream error code 500
--- request
GET /specific_status
--- more_headers
X-Test-Upstream-Status: 500
--- error_code: 500
--- response_body
upstream status: 500
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little confused, why do special treatments for upstream status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a mock that I mock the upstream status.
You can see t/lib/server.lua.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, why doesn’t the upstream 5xx show the 5xx page of Apache APISIX?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, why doesn’t the upstream 5xx show the 5xx page of Apache APISIX?

The upstream 5xx has its own mean.There maybe contains the error info like `{"code": 5xx, "error_msg": "xxx"}.
So IMO we shouldn't modify it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do users need to care about the error of the Apache APISIX or the upstream error? I remember that there are already corresponding HTTP headers to distinguish

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some situations. The info in the response body is useful. The user will need the upstream error info.
cc @tokers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moonming We should keep the upstream 4xx/5xx pages intact by default, but we may add a switch like:

proxy_intercept_errors on | off;

This is a standard Nginx directive.

Copy link
Member

@moonming moonming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR, what was the data returned by 5xx and 4xx?

@tokers
Copy link
Contributor

tokers commented Apr 19, 2021

I have no other questions but one:

  1. Make sure it won't overwrite the 4xx and 5xx pages generated by upstream.
  2. For those 4xx and 5xx codes generated by APISIX, we may need more information like "IP is forbidden" (ip-restriction plugin).

For 1, we may have a switch to control whether or not to override the upstream.

@moonming
Copy link
Member

Before this PR, what was the data returned by 5xx and 4xx?

any response? @starsz

@starsz
Copy link
Contributor Author

starsz commented Apr 19, 2021

Before this PR, what was the data returned by 5xx and 4xx?

any response? @starsz

Let me test and list the response.

@starsz
Copy link
Contributor Author

starsz commented Apr 19, 2021

Before this PR, what was the data returned by 5xx and 4xx?

any response? @starsz

Let me test and list the response.

The internal error:
500:

<html>
<head><title>500 Internal Server Error</title></head>
<body>
<center><h1>500 Internal Server Error</h1></center>
<hr><center>openresty</center>
</body>
</html>

502:

<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>openresty</center>
</body>
</html>

503:

<html>
<head><title>503 Service Temporarily Unavailable</title></head>
<body>
<center><h1>503 Service Temporarily Unavailable</h1></center>
<hr><center>openresty</center>
</body>
</html>

504:

<html>
<head><title>504 Gateway Time-out</title></head>
<body>
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>openresty</center>
</body>
</html>

400:

<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>openresty</center>
</body>
</html>

401:

<html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>openresty</center>
</body>
</html>

404:

<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>openresty</center>
</body>
</html>

@moonming
Copy link
Member

Then your PR did not solve the issue @starsz

@moonming
Copy link
Member

please read the issue again

@starsz
Copy link
Contributor Author

starsz commented Apr 20, 2021

Then your PR did not solve the issue @starsz

I am confused. This PR can solve the issue. The response I give is before this PR.
Can you give more details about why this PR can't solve the issue?

By the way, I will fix the CI first.

@moonming
Copy link
Member

Then your PR did not solve the issue @starsz

I am confused. This PR can solve the issue. The response I give is before this PR.

Can you give more details about why this PR can't solve the issue?

By the way, I will fix the CI first.

please make sure you read the issue and thread in mailinglist

@tokers
Copy link
Contributor

tokers commented Apr 21, 2021

@starsz Conflicts should be resolved.

@starsz
Copy link
Contributor Author

starsz commented Apr 22, 2021

Then your PR did not solve the issue @starsz

I am confused. This PR can solve the issue. The response I give is before this PR.
Can you give more details about why this PR can't solve the issue?
By the way, I will fix the CI first.

please make sure you read the issue and thread in mailing list

Hi, @moonming.I read the email again.

The openresty updated the 50x.html.
If we use the openresty's default conf or nginx default conf. There is the following configuration:

error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

So that we can see the HTML that updated by the openresty.

But in apisix, we don't set the error page in config.See the ngx_tpl.lua.So we wouldn't see the 50x.html updated by the openresty.

BTW, I think my implementation is too complicated. Can we create html directory and put our html in it? Then we can get the html if an error occurred.

@moonming
Copy link
Member

any update?

@moonming
Copy link
Member

@starsz ping

@starsz
Copy link
Contributor Author

starsz commented Apr 29, 2021

any update?

Use another PR #4164 to fix this issue.
So this PR can be closed.

@starsz starsz closed this Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

request help: custom index.html 4xx.html 5xx.html in Apache APISIX
5 participants