Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Proxy CORS on end server being down or timing out

Tags:

cors

proxy

apache

I am using angularjs on the UI and it cant tell the difference between the server being down or a timeout both respond with something like the following. This is due to cors. When server is down or a request times out apache does not add the cors header.

"{"data":null,"status":0,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"https://api.domain.com/containers/60539","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":""}"

How can I make sure that I get the proper 502/503 statuses back from apache on the GET request while having 200 on the options?

Thank you!

Current Config:

<VirtualHost *:443>
  ServerName api.domain.com
  <IfModule proxy_module>
    ProxyRequests Off
    SSLProxyEngine On
    SSLProxyVerify none 
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    ProxyPass / 1.1.1.1
    Header set Access-Control-Allow-Origin "*"
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </IfModule>
  SSLEngine on
  SSLCertificateFile "${WILDCARDSSLCRT}"
  SSLCertificateKeyFile "${WILDCARDSSLKEY}"
  SSLCertificateChainFile "${WILDCARDSSLCHAIN}"
</VirtualHost>
like image 876
Jegsar Avatar asked Oct 27 '25 07:10

Jegsar


1 Answers

Instead of Header set use Header always set:

Header always set Access-Control-Allow-Origin "*"

https://httpd.apache.org/docs/current/mod/mod_headers.html#Header explains:

The table that corresponds to always is used for locally generated error responses as well as successful responses.


And a couple of guides with some good guidance:

  • Getting CORS to work with Apache
  • Setting CORS (cross-origin resource sharing) on Apache with correct response headers allowing everything through
like image 105
sideshowbarker Avatar answered Oct 29 '25 09:10

sideshowbarker