Apache: X-Request-ID like in Heroku

guettli asked:

I like X-Request-ID:

The Heroku router generates a unique request ID for every incoming HTTP request that it receives. This unique ID is then passed to your application as an HTTP header called X-Request-ID.

From https://devcenter.heroku.com/articles/http-request-id

How can I configure Apache to provide X-Request-ID which is different, even if a multi-threaded MPM gets used?

My answer:


You need to do two things:

  1. Load the unique_id_module. This provides the UNIQUE_ID environment variable which serves this purpose.

    LoadModule mod_unique_id
    
  2. Copy the UNIQUE_ID into the X-Request-ID header in the appropriate virtual host using the RequestHeader directive.

    RequestHeader setifempty X-Request-ID %{UNIQUE_ID}e
    ProxyPass ...
    ProxyPassReverse ...
    

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.