Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alertor/c9cacc43fea650f540e0d44c603e9254 to your computer and use it in GitHub Desktop.
Save alertor/c9cacc43fea650f540e0d44c603e9254 to your computer and use it in GitHub Desktop.
Mimicking CORS preflight responses in Apache
<VirtualHost _default_:443>
ServerName yourhost
ServerAdmin someperson@yourorg.com
SSLEngine on
SSLCertificateFile /etc/ssl/private/yourorg.com.crt
SSLCertificateKeyFile /etc/ssl/private/yourorg.com.key
SSLCertificateChainFile /etc/ssl/private/chain.pem
SSLProxyEngine On
ProxyRequests Off
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ - [ENV=PREFLIGHT:true]
SetEnvIf Origin "^(.*)$" ORIGIN=$0
Header always set Access-Control-Allow-Origin %{ORIGIN}e env=PREFLIGHT
Header always set Access-Control-Allow-Credentials "true" env=PREFLIGHT
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS" env=PREFLIGHT
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=204,L]
ProxyPass / http://host.yourorg.com:8087/
ProxyPassReverse / http://host.yourorg.com:8087/
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment