You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/09/24 09:13:01 UTC

[GitHub] [apisix] zhendongcmss opened a new issue, #7987: help request:

zhendongcmss opened a new issue, #7987:
URL: https://github.com/apache/apisix/issues/7987

   ### Description
   
   when apisix return 5xx http code, I want customize the return description and error page.  It include two sides.
   
   1. The short description of the error code. For example `HTTP/1.1 503 Service Temporarily Unavailable`, I want modify it to `HTTP/1.1 503 Service Unavailable`.    I grep `Service Temporarily Unavailable` not found but fount it on nginx.  https://github.com/nginx/nginx/blob/master/src/http/ngx_http_header_filter_module.c#L120
   2. The default error html page. I want return XML format string not html. For example :
    ```
   <html>
   <head><title>502 Bad Gateway</title></head>
   <body>
   <center><h1>502 Bad Gateway</h1></center>
   <hr><center>openresty</center>
   </body>
   </html>
   ```
   to 
   ```
   <?xml version="1.0" encoding="UTF-8" ?>
   <error>502</error>
   ```
   
   I found the error pages were defined on openresty and nginx.
   
   https://github.com/openresty/openresty/blob/master/patches/nginx-1.11.2-builtin_error_page_footer.patch#L10
   
   
   Is it possible to just modify the source code of apisix above two points?
   
   ### Environment
   
   - APISIX version (run `apisix version`): 2.10.1
   - Operating system (run `uname -a`): centos7
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):1.19.3.2
   - etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):3.4.14
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] boekkooi-lengoo commented on issue #7987: help request: customize the return description and error page

Posted by GitBox <gi...@apache.org>.
boekkooi-lengoo commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-1363711257

   Hey all, 
   So I hit the same issue where a 401 was returned by the `openid` plugin and it shows the nginx/openresty [error page](https://github.com/api7/apisix-nginx-module/blob/main/patch/1.21.4/nginx-error_page_contains_apisix.patch).
   
   To be it feels very inconsistent that some plugins return error like `{"error_msg": "...."}` and then at other moment you need to deal with nginx error pages. 
   
   Any how in my case I used the following code to match the error message up.
   
   ```YAML
     configurationSnippet:
       # Based on
       # - https://blog.adriaan.io/one-nginx-error-page-to-rule-them-all.html
       # - https://gist.github.com/lextoumbourou/d6221deb818da4f342ea
       httpStart: |
         more_clear_headers Server;
         
         map $status $status_text {
           400 'Bad Request';
           401 'Unauthorized';
           402 'Payment Required';
           403 'Forbidden';
           404 'Not Found';
           405 'Method Not Allowed';
           406 'Not Acceptable';
           407 'Proxy Authentication Required';
           408 'Request Timeout';
           409 'Conflict';
           410 'Gone';
           411 'Length Required';
           412 'Precondition Failed';
           413 'Payload Too Large';
           414 'URI Too Long';
           415 'Unsupported Media Type';
           416 'Range Not Satisfiable';
           417 'Expectation Failed';
           418 'I\'m a teapot';
           421 'Misdirected Request';
           422 'Unprocessable Entity';
           423 'Locked';
           424 'Failed Dependency';
           425 'Too Early';
           426 'Upgrade Required';
           428 'Precondition Required';
           429 'Too Many Requests';
           431 'Request Header Fields Too Large';
           451 'Unavailable For Legal Reasons';
           500 'Internal Server Error';
           501 'Not Implemented';
           502 'Bad Gateway';
           503 'Service Unavailable';
           504 'Gateway Timeout';
           505 'HTTP Version Not Supported';
           506 'Variant Also Negotiates';
           507 'Insufficient Storage';
           508 'Loop Detected';
           510 'Not Extended';
           511 'Network Authentication Required';
           default 'Something is wrong';
         }
         map $http_accept $extension {
           default html;
           ~*application/json json;
         }
       httpSrv: |
         error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 425 426 428 429 431 451 500 501 502 503 504 505 506 507 508 510 511 @error_$extension;
   
         location @error_json {
           types { } default_type "application/json; charset=utf-8";
           echo '{"error_msg": "$status_text"}';
         }
         location @error_html {
           types { } default_type "text/html; charset=utf-8";
           echo '<html><head><title>$status $status_text</title></head><body><center><h1>$status $status_text</h1></center></html>';
         }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: customize the return description and error page [apisix]

Posted by "nphariharan (via GitHub)" <gi...@apache.org>.
nphariharan commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-1770722435

   Thanks for the help. The below is the working config.yaml. (tested in APISIX 3.6.0 - Standalone mode). Some body wants this feature, they can quickly take this working configuration. You can customize below code as per your needs.
   
   nginx_config:
     http_configuration_snippet: |
       more_clear_headers Server;
       map $status $status_text {
         400 'Bad Request';
         401 'Unauthorized';
         402 'Payment Required';
         403 'Forbidden';
         404 'Not Found';
         405 'Method Not Allowed';
         406 'Not Acceptable';
         407 'Proxy Authentication Required';
         408 'Request Timeout';
         409 'Conflict';
         410 'Gone';
         411 'Length Required';
         412 'Precondition Failed';
         413 'Payload Too Large';
         414 'URI Too Long';
         415 'Unsupported Media Type';
         416 'Range Not Satisfiable';
         417 'Expectation Failed';
         418 'I\'m a teapot';
         421 'Misdirected Request';
         422 'Unprocessable Entity';
         423 'Locked';
         424 'Failed Dependency';
         425 'Too Early';
         426 'Upgrade Required';
         428 'Precondition Required';
         429 'Too Many Requests';
         431 'Request Header Fields Too Large';
         451 'Unavailable For Legal Reasons';
         500 'Internal Server Error';
         501 'Not Implemented';
         502 'Bad Gateway';
         503 'Service Unavailable';
         504 'Gateway Timeout';
         505 'HTTP Version Not Supported';
         506 'Variant Also Negotiates';
         507 'Insufficient Storage';
         508 'Loop Detected';
         510 'Not Extended';
         511 'Network Authentication Required';
         default 'Something is wrong';
       }
       map $http_accept $extension {
         default html;
         ~*application/json json;
       }
   
     http_server_configuration_snippet: |
       error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 425 426 428 429 431 451 500 501 502 503 504 505 506 507 508 510 511 @error_$extension;
   
       location @error_json {
         types { } default_type "application/json; charset=utf-8";
         echo '{"error_msg": "$status_text"}';
       }
       location @error_html {
         types { } default_type "text/html; charset=utf-8";
         echo '<html><head><title>$status $status_text</title></head><body><center><h1>$status $status_text</h1></center></html>';
       }


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] boekkooi-lengoo commented on issue #7987: help request: customize the return description and error page

Posted by "boekkooi-lengoo (via GitHub)" <gi...@apache.org>.
boekkooi-lengoo commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-1493966655

   Hey @laizuan,
   
   I think that was the name on the help chart in any case httpStart is the one defined under https://github.com/apache/apisix/blob/809ba09b26ddd62e0efa612f85e90d1aa938ce02/conf/config-default.yaml#L176 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] monkeyDluffy6017 commented on issue #7987: help request: customize the return description and error page

Posted by GitBox <gi...@apache.org>.
monkeyDluffy6017 commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-1259196165

   For 1, OpenRest doesn't provide a api to change the HTTP status reason now, but i found a stale pr: https://github.com/openresty/lua-nginx-module/pull/870, it could resolve your problem, but it is blocked by `need test cases`, i will push this pr.
   
   For 2,  please follow what @tokers suggested, and if you want to handle with the upstream status code, please add directive `proxy_intercept_errors`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tokers commented on issue #7987: help request: customize the return description and error page

Posted by GitBox <gi...@apache.org>.
tokers commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-1257170581

   @zhendongcmss You may try to use the `error_page` directive. See https://apisix.apache.org/docs/apisix/customize-nginx-configuration/ to learn how to inject this directive to APISIX.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: customize the return description and error page [apisix]

Posted by "JoonaHa (via GitHub)" <gi...@apache.org>.
JoonaHa commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-2059266727

   Thanks @boekkooi-lengoo I got it to work. I had misconfigured plugin which caused an error to return from lua instead of nginx.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: customize the return description and error page [apisix]

Posted by "pshettyk (via GitHub)" <gi...@apache.org>.
pshettyk commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-1770575130

   Super.  It worked.  Thanks very much. I had to put contents of "httpSrv" in "http_server_configuration_snippet" and "httpStart" in "http_configuration_snippet" section of config.xml.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: customize the return description and error page [apisix]

Posted by "boekkooi-lengoo (via GitHub)" <gi...@apache.org>.
boekkooi-lengoo commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-2056470903

   Hey @JoonaHa 
   
   I just did an update from 3.8.0 to 3.9.0 and this trick still work like a charm for me.
   Maybe there is some error in the logs or you forgot to add the header `Accept: application/json` while testing?
   
   Cheers,
   Warnar


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: customize the return description and error page [apisix]

Posted by "lvillis (via GitHub)" <gi...@apache.org>.
lvillis commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-1787575511

   Thanks @boekkooi-lengoo @nphariharan
   
   Apisix v3.x requires the following configuration to take effect.
   
   ```yaml
   apisix:
     # .....
   nginx_config:
     http_configuration_snippet: |
       more_clear_headers Server;
       
       map $status $status_text {
       400 'Bad Request';
       401 'Unauthorized';
       402 'Payment Required';
       403 'Forbidden';
       404 'Not Found';
       405 'Method Not Allowed';
       406 'Not Acceptable';
       407 'Proxy Authentication Required';
       408 'Request Timeout';
       409 'Conflict';
       410 'Gone';
       411 'Length Required';
       412 'Precondition Failed';
       413 'Payload Too Large';
       414 'URI Too Long';
       415 'Unsupported Media Type';
       416 'Range Not Satisfiable';
       417 'Expectation Failed';
       418 'I\'m a teapot';
       421 'Misdirected Request';
       422 'Unprocessable Entity';
       423 'Locked';
       424 'Failed Dependency';
       425 'Too Early';
       426 'Upgrade Required';
       428 'Precondition Required';
       429 'Too Many Requests';
       431 'Request Header Fields Too Large';
       451 'Unavailable For Legal Reasons';
       500 'Internal Server Error';
       501 'Not Implemented';
       502 'Bad Gateway';
       503 'Service Unavailable';
       504 'Gateway Timeout';
       505 'HTTP Version Not Supported';
       506 'Variant Also Negotiates';
       507 'Insufficient Storage';
       508 'Loop Detected';
       510 'Not Extended';
       511 'Network Authentication Required';
       default 'Something is wrong';
       }
       map $http_accept $extension {
       default html;
       ~*application/json json;
       }
     http_server_configuration_snippet: |
       error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 425 426 428 429 431 451 500 501 502 503 504 505 506 507 508 510 511 @error_$extension;
   
         location @error_json {
           types { } default_type "application/json; charset=utf-8";
           echo '{"error_msg": "$status_text"}';
         }
         location @error_html {
           types { } default_type "text/html; charset=utf-8";
           echo '<html><head><title>$status $status_text</title></head><body><center><h1>$status $status_text</h1></center></html>';
         }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: customize the return description and error page [apisix]

Posted by "JoonaHa (via GitHub)" <gi...@apache.org>.
JoonaHa commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-2049846882

   Hi @lvillis @boekkooi-lengoo 
   Does setup this still work for you? I tried with Apisix 3.9 and 3.8
   I tried by passing the values using the Helm chart's `configurationSnippet.httpStart` and `configurationSnippet.httpSrv`
   Also tried by modifying config.yaml directly and in both cases container included the correct fields in file `/usr/local/apisix/conf/nginx.conf`
   Still no luck.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] laizuan commented on issue #7987: help request: customize the return description and error page

Posted by "laizuan (via GitHub)" <gi...@apache.org>.
laizuan commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-1493370742

   @boekkooi-lengoo 
   
   hi I didn't find the 'configurationSnippet' configuration in 'default-config.yaml', could you please tell me how you configured it? thank you
   
    


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: customize the return description and error page [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 closed issue #7987: help request: customize the return description and error page
URL: https://github.com/apache/apisix/issues/7987


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] help request: customize the return description and error page [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on issue #7987:
URL: https://github.com/apache/apisix/issues/7987#issuecomment-1851486443

   considered resolved


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org