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 50x html for error page #4164

Merged
merged 29 commits into from
May 11, 2021
Merged

feat: add 50x html for error page #4164

merged 29 commits into from
May 11, 2021

Conversation

starsz
Copy link
Contributor

@starsz starsz commented Apr 29, 2021

What this PR does / why we need it:

As we discussed in the email, we should have our own 50x HTML and index.html.Index.html maybe not necessary because of apisix is a grateway, there is no opportunity to show the index.html.

This PR is about to add 50x html into error_page. So when we had an error in apisix, we will show the html.
If the upstream returns 5xx error, we will show the upstream response rather than the 50x.html.

Fix: #3251

Pre-submission checklist:

  • Did you explain what problem does this PR solve? 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 changed the title feat: add 50x html feat: add 50x html for error page Apr 29, 2021
@starsz starsz mentioned this pull request Apr 29, 2021
4 tasks
@starsz starsz marked this pull request as draft April 30, 2021 01:04
@starsz starsz marked this pull request as ready for review May 9, 2021 16:42
@starsz starsz requested review from spacewander, membphis, tokers and moonming and removed request for spacewander and membphis May 9, 2021 16:42
apisix/init.lua Outdated
@@ -620,6 +619,15 @@ end

function _M.http_log_phase()
local api_ctx = common_phase("log")
if not api_ctx then
local ctx = ctxdump.apply_ngx_ctx(ngx_var.ctx_ref)
Copy link
Member

Choose a reason for hiding this comment

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

Why not reapply the ctx in http_header_filter_phase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good. Let me fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Please review it again.

@@ -617,6 +642,17 @@ http {
proxy_pass $upstream_mirror_host$request_uri;
}
{% end %}

location = /50x.html {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to use named location?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really good to do that.Because we will use "50x.html" to search in the "html" directory.

Copy link
Member

Choose a reason for hiding this comment

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

So the log phase might get a rewritten URL instead of the original one? This is not good news...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I found a new way. We can use "try_files" to get the html.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Please review it again.

@@ -290,6 +293,17 @@ http {
apisix.http_control()
}
}

location = /50x.html {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a named location or internal location.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@@ -367,6 +381,17 @@ http {
apisix.http_admin()
}
}

location = /50x.html {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

apisix/init.lua Show resolved Hide resolved
html/50x.html Outdated
@@ -0,0 +1,38 @@
<!--
Copy link
Member

Choose a reason for hiding this comment

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

Can we put this file into a Lua script like ngx_tpl.lua? So that there is no need to create an extra directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Please review it again.

@@ -605,6 +611,9 @@ local function start(env, ...)
local cmd_logs = "mkdir -p " .. env.apisix_home .. "/logs"
util.execute_cmd(cmd_logs)

local cmd_html = "mkdir -p " .. env.apisix_home .. "/html"
Copy link
Member

Choose a reason for hiding this comment

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

Need to add it to gitignore:

conf/nginx.conf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Please review it again.

@@ -605,6 +614,7 @@ local function start(env, ...)
local cmd_logs = "mkdir -p " .. env.apisix_home .. "/logs"
util.execute_cmd(cmd_logs)


Copy link
Contributor

Choose a reason for hiding this comment

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

Why adding an empty line here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Please review it again.

t/error_page/error_page.t Show resolved Hide resolved
apisix/init.lua Outdated
@@ -534,6 +533,10 @@ end


function _M.http_header_filter_phase()
if not ngx.ctx or not ngx.ctx.api_ctx then
ngx.ctx = ctxdump.apply_ngx_ctx(ngx_var.ctx_ref)
Copy link
Contributor

Choose a reason for hiding this comment

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

Stash ngx.ctx unconditionally but checking the existence of ngx.ctx , this behavior leaks some keys for ngx.ctx tables (for those requests which doesn't make internal redirect).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Please review it again.

t/APISIX.pm Outdated
@@ -426,6 +429,18 @@ _EOC_
more_clear_headers Date;
}

location \@50x.html {
set \$error_page 'true';
Copy link
Member

Choose a reason for hiding this comment

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

Better to use from_error_page instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@@ -74,3 +74,4 @@ ci/openwhisk-utilities/
# release tar package
*.tgz
release/*
html/*
Copy link
Member

Choose a reason for hiding this comment

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

To make the license check pass, also need to change

# Exclude CI files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@tokers tokers merged commit adc9977 into apache:master May 11, 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
3 participants