0

I've haproxy server which is routing requests to different web service instance based on rules. The web service instances have apache running at port 80. Now, I'm trying to set some expiry header by using mod_expires.

This is my entry in httpd.conf.

ExpiresActive On

ExpiresByType text/html                     "access plus 24 hours"

ExpiresByType text/htm                      "access plus 24 hours"

ExpiresByType image/gif                     "access plus 24 hours"

ExpiresByType application/json              "access plus 24 hours"

I can see max-age being set for Cache-control if I directly hit the server IP. But if I go through haproxy, none of the Cache-control headers are being set. They are always "keep-alive". The haproxy is routing requests to apache server in port 80.

I'm running on CentOS 6.

Do I need some configuration in haproxy to support this? Any pointers will be appreciated.

Edit:

Here's the haproxy config.


#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    log         127.0.0.1 local2
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode        http
#    log         global
    option      dontlognull
    option      httpclose
    option      httplog
    option      forwardfor
    option      redispatch
    timeout connect 10000 # default 10 second time out if a backend is not found
    timeout client 300000
    timeout server 300000
    monitor-uri /index.html
    maxconn     60000
    retries     3

#
# Host HA-Proxy's web stats on Port 81.
listen stats :1936
    mode http
    stats enable
    stats hide-version
    stats realm Haproxy\ Statistics
    stats uri /
    stats auth Username:Password

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  main *:80
    log 127.0.0.1 local2
    capture request  header    X-Forwarded-For      len 500
    capture request  header    Host                 len 500
    capture response header    X-Query-Result       len 100
    acl url_webservice path_beg -i /community /toolkit /domain
    use_backend webservice          if url_webservice
backend webservice
    balance     roundrobin
    server      webservice1 xx.xx.xx.xxx:80 check

-Thanks, Shamik

  • Can you post your haproxy config? – cuonglm Apr 11 '15 at 2:02
  • @cuonglm .. I've added the haproxy configuration – Shamik Apr 11 '15 at 2:11
  • If you use httplog, all the header will be logged in log file. Can you check it and verify if cache-control was set? – cuonglm Apr 11 '15 at 4:10
  • The only log which gets generated is haproxy configured under /var/log. I don't see any cache-control header in there. Here's an example : Apr 11 14:46:52 127.0.0.1 haproxy[9873]: 10.191.20.35:17626 [11/Apr/2015:14:46:52.492] main webservice/webservice1 40/0/1/19/62 200 2299 - - ---- 17/17/0/0/0 0/0 {54.203.36.xx|test-site.com} {1} "GET //service/rest/help/resource/help/feed/?maxresults=1&origin=A HTTP/1.1" – Shamik Apr 11 '15 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.