Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Last active February 15, 2022 20:54
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 haproxytechblog/861381eb2979989393eebbd79d3ea240 to your computer and use it in GitHub Desktop.
Save haproxytechblog/861381eb2979989393eebbd79d3ea240 to your computer and use it in GitHub Desktop.
Enabling CORS in HAProxy
frontend www
bind :80
# Add a response header
http-response add-header X-XSS-Protection "1; mode=block"
# Remove a response header
http-response del-header X-Powered-By
# Change a response header
http-response set-header Via "HTTP/2.0 haproxy1"
default_backend webservers
$ haproxy -vv | grep Lua
Built with Lua version: Lua 5.3.5
global
lua-load /etc/haproxy/cors.lua
Origin: http://example.com
listen api
bind :80
http-request lua.cors "GET,PUT,POST" "example.com" "*"
http-response lua.cors
server s1 192.168.50.20 check
server s2 192.168.50.21 check
server s3 192.168.50.22 check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment