This discussion is archived
2 Replies Latest reply: Feb 7, 2013 8:41 AM by Nahawand-920565 RSS

Handle 502 errors from origin server - oracle iPlanet web server 7 update13

Nahawand-920565 Newbie
Currently Being Moderated
Hello all,

My setup is as follows: Oracle iplanet web server accepts requests from clients (web browsers) and reverse proxies these requests to the back-end (origin) server.

When the origin server is not available for any reason, a 502 error is generated by the Reverse proxy and sent to the client. I am trying to catch this error and handle it by redirecting the client to another url, say, http://www.google.ca. I have tried to implement this using multiple methods but they all failed.


I tried three types of codes and they all failed:

1.
*<If $code =~ "502">*
Output fn="redirect" from="/" url="https://www.google.ca"
*</If>*

2.
*<If $restarted>*
Output fn="redirect" from="/" url="https://www.google.ca"
*</If>*

*<If $code =~ "502">*
Error fn="restart" uri="$uri"
*</If>*

3.
*<If $code =~ "502">*
Error fn="redirect" url="http://www.google.ca"
*</If>*


Do you guys have any ideas or suggestions?

Edited by: Nahawand-920565 on Feb 7, 2013 12:05 PM
  • 1. Re: Handle 502 (bad gateway) error from origin server
    Nahawand-920565 Newbie
    Currently Being Moderated
    Here is my obj.conf file:

    <Object name="default">
    NameTrans fn="map" from="/" name="reverse-proxy-/" to="http:/"

    <If $code =~ "502">
    Error fn="redirect" url="http://www.google.ca"
    </If>


    PathCheck fn="uri-clean"
    PathCheck fn="check-acl" acl="default"
    PathCheck fn="find-pathinfo"
    PathCheck fn="find-index" index-names="index.html,home.html,index.jsp"
    ObjectType fn="type-by-extension"
    ObjectType fn="force-type" type="text/plain"
    Service method="(GET|HEAD)" type="magnus-internal/directory" fn="index-common"
    Service method="(GET|HEAD|POST)" type="\*~magnus-internal/*" fn="send-file"
    AddLog fn="flex-log" name="default" iponly="false"
    </Object>

    <Object name="send-precompressed">
    PathCheck fn="find-compressed"
    </Object>

    <Object name="compress-on-demand">
    Output fn="insert-filter" filter="http-compression"
    </Object>

    <Object ppath="http:*">
    Service fn="proxy-retrieve" method="*"
    </Object>

    <Object name="stats-xml">
    Service fn="stats-xml"
    </Object>

    <Object name="reverse-proxy-/">
    Route fn="set-origin-server" server="http://backend.origin.server.com"
    </Object>
  • 2. Re: Handle 502 (bad gateway) error from origin server
    Nahawand-920565 Newbie
    Currently Being Moderated
    Here is the error log set to finest. Note that even though the error log shows "request proceed" for the redirect SAF in the Error directive, the browser does not get redirected to google. Instead, it simply gets a white page with an HTTP code of 502. If, however, I take the Error directive outside of the if statement, then all requests coming to the server, will be redirected to google. So, it appears that the combination of the if statement and the Error directive does not work. Could this be a bug? Anyways, here is the error log output:

    Processing / for 93.83.73.63 using NSAPI
    for host 93.83.73.63 trying to GET /, process-uri-objects reports: processing objects for URI /
    for host 93.83.73.63 trying to GET /, process-uri-objects reports: processing object name="default"
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="map" from="" name="reverse-proxy-/" to="http:/" Directive="NameTrans"
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="map" from="" name="reverse-proxy-/" to="http:/" Directive="NameTrans" returned 0 (REQ_PROCEED)
    for host 93.83.73.63 trying to GET /, process-uri-objects reports: processing object name="reverse-proxy-/"
    for host 93.83.73.63 trying to GET /, process-uri-objects reports: processing object ppath="http:*"
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="uri-clean" Directive="PathCheck"
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="uri-clean" Directive="PathCheck" returned -2 (REQ_NOACTION)
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="find-pathinfo" Directive="PathCheck"
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="find-pathinfo" Directive="PathCheck" returned -2 (REQ_NOACTION)
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="find-index" index-names="index.html,home.html,index.jsp" Directive="PathCheck"
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="find-index" index-names="index.html,home.html,index.jsp" Directive="PathCheck" returned -2 (REQ_NOACTION)
    acl: calling getter for (attr=user; method=basic, dbtype=file)
    acl: calling getter for (attr=isvalid-password; method=basic, dbtype=file)
    acl: calling getter for (attr=raw-user; method=basic, dbtype=file)
    acl: calling getter for (attr=authorization; method=basic, dbtype=file)
    acl: getter for (attr=authorization; method=basic, dbtype=file) returns -1
    acl: getter for (attr=raw-user; method=basic, dbtype=file) returns -1
    file authdb: Authenticating user [username]
    file authdb: Authentication succeeded for [username] (basic)
    acl: getter for (attr=isvalid-password; method=basic, dbtype=file) returns -1
    acl: getter for (attr=user; method=basic, dbtype=file) returns -1
    acl user: user [username] matched user = (username)
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="type-by-extension" Directive="ObjectType"
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="type-by-extension" Directive="ObjectType" returned 0 (REQ_PROCEED)
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="force-type" type="text/plain" Directive="ObjectType"
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="force-type" type="text/plain" Directive="ObjectType" returned 0 (REQ_PROCEED)

    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="proxy-retrieve" method="*" Directive="Service"
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="set-origin-server" server="http://backend.origin.server.com" Directive="Route" magnus-internal=""
    for host 93.83.73.63 trying to GET /, set-origin-server reports: using server backend.origin.server.com:80
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="set-origin-server" server="http://backend.origin.server.com" Directive="Route" magnus-internal="" returned 0 (REQ_PROCEED)
    for host 93.83.73.63 trying to GET /, service-http reports: attempting to contact backend.origin.server.com:80
    for host 93.83.73.63 trying to GET /, attempting to resolve backend.origin.server.com
    for host 93.83.73.63 trying to GET /, attempting to connect to 10.20.30.40:80
    for host 93.83.73.63 trying to GET /, connected to 10.20.30.40:80
    for host 93.83.73.63 trying to GET /, service-http reports: HTTP7766: error reading response header (Connection reset by peer)

    for host 93.83.73.63 trying to GET /, service-http reports: retrying request (retry 1 of 3)
    for host 93.83.73.63 trying to GET /, service-http reports: attempting to contact backend.origin.server.com:80
    for host 93.83.73.63 trying to GET /, attempting to resolve backend.origin.server.com
    for host 93.83.73.63 trying to GET /, attempting to connect to 10.20.30.40:80
    for host 93.83.73.63 trying to GET /, connected to 10.20.30.40:80
    [07/Feb/2013:11:08:32] failure (12754): for host 93.83.73.63 trying to GET /, service-http reports: HTTP7766: error reading response header (Connection reset by peer)
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="set-origin-server" server="http://backend.origin.server.com" Directive="Route" magnus-internal=""
    for host 93.83.73.63 trying to GET /, set-origin-server reports: using server backend.origin.server.com:80
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="set-origin-server" server="http://backend.origin.server.com" Directive="Route" magnus-internal="" returned 0 (REQ_PROCEED)

    for host 93.83.73.63 trying to GET /, service-http reports: retrying request (retry 2 of 3)
    for host 93.83.73.63 trying to GET /, service-http reports: attempting to contact backend.origin.server.com:80
    for host 93.83.73.63 trying to GET /, attempting to resolve backend.origin.server.com
    for host 93.83.73.63 trying to GET /, attempting to connect to 10.20.30.40:80
    for host 93.83.73.63 trying to GET /, connected to 10.20.30.40:80
    [07/Feb/2013:11:08:32] failure (12754): for host 93.83.73.63 trying to GET /, service-http reports: HTTP7766: error reading response header (Connection reset by peer)
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="set-origin-server" server="http://backend.origin.server.com" Directive="Route" magnus-internal=""
    for host 93.83.73.63 trying to GET /, set-origin-server reports: using server backend.origin.server.com:80
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="set-origin-server" server="http://backend.origin.server.com" Directive="Route" magnus-internal="" returned 0 (REQ_PROCEED)

    for host 93.83.73.63 trying to GET /, service-http reports: retrying request (retry 3 of 3)
    for host 93.83.73.63 trying to GET /, service-http reports: attempting to contact backend.origin.server.com:80
    for host 93.83.73.63 trying to GET /, attempting to resolve backend.origin.server.com
    for host 93.83.73.63 trying to GET /, attempting to connect to 10.20.30.40:80
    for host 93.83.73.63 trying to GET /, connected to 10.20.30.40:80
    [07/Feb/2013:11:08:32] failure (12754): for host 93.83.73.63 trying to GET /, service-http reports: HTTP7766: error reading response header (Connection reset by peer)
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="set-origin-server" server="http://backend.origin.server.com" Directive="Route" magnus-internal=""

    for host 93.83.73.63 trying to GET /, set-origin-server reports: using server backend.origin.server.com:80
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="set-origin-server" server="http://backend.origin.server.com" Directive="Route" magnus-internal="" returned 0 (REQ_PROCEED)
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="proxy-retrieve" method="*" Directive="Service" returned -1 *(REQ_ABORTED)*
    for host 93.83.73.63 trying to GET /, =~ reports: Subject "502" matches pattern "502" with 0 capturing subpattern(s)
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="redirect" url="http://www.google.ca" Directive="Error"
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="redirect" url="http://www.google.ca" Directive="Error" returned 0 *(REQ_PROCEED)*
    for host 93.83.73.63 trying to GET /, func_exec reports: executing fn="flex-log" name="default" iponly="false" Directive="AddLog"
    for host 93.83.73.63 trying to GET /, func_exec reports: fn="flex-log" name="default" iponly="false" Directive="AddLog" returned 0 (REQ_PROCEED)

    Edited by: Nahawand-920565 on Feb 7, 2013 11:40 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points