Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7747561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:33:39+00:00 2026-06-01T10:33:39+00:00

How to set a custom log format for nginx, so that request got parsed

  • 0

How to set a custom log format for nginx, so that request got parsed and its parts are logged separate?

We serve a picture file to count mail opens. The url to the picture varies, but follows the rule:

http://www.server.com/counter/XXXXX/YYYYY/dailymail.gif

XXXXX – id of email campaign;
YYYYY – recipient id.

There’s a separate log for /counter location, which I’d like to give a format like

XXXXX   YYYYY    DATETIME

Location section looks like

    location    ~* ^counter/([0-9]+)/([^/]+)/dailymail\.gif$ {
        access_log /var/log/mailopened.log
        alias /var/www/site.com/1x1.gif?cid=$1&uid=$2&type=daily;
    }

So I have the values in variables $1 and $2. How can I use them in the log format?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:33:41+00:00Added an answer on June 1, 2026 at 10:33 am

    log_format directive is allowed at http level only, so you have to define it in terms of other variables, e.g.

    http {
      log_format tracking "$xxxx $yyyy $time_local";
    

    Later, in your location, just set these variables and log in tracking format:

    location ~* ^counter/([0-9]+)/([^/]+)/dailymail\.gif$ {
      set $xxxx $1;
      set $yyyy $2;
      access_log /var/log/mailopened.log tracking;
      alias /var/www/site.com/1x1.gif?cid=$1&uid=$2&type=daily;
    }
    

    With recent versions of Nginx and PCRE library it’s possible to omit set calls and name the captures explicitly in location (thanks to @kolbyjack):

    location ~* ^counter/(?<xxxx>[0-9]+)/(?<yyyy>[^/]+)/dailymail\.gif$ {
      access_log /var/log/mailopened.log tracking;
      alias /var/www/site.com/1x1.gif?cid=$1&uid=$2&type=daily;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a custom OpenID provider that I'd like to use to log in
I have a function that I set custom key and value to it and
I want to create a custom set that will automatically convert objects into a
Here's the problem I'm having, I've got a set of logs that can grow
I'm trying to set up a custom backend that queries another database, for which
How to set custom header logo on your Track Wiki project page? How to
How do I set custom HTTP headers on an ESB proxy service Out Sequence?
I just can't figure it out how to set custom validator messages in Zend_Form
How can I set a custom filter in my code to ignore accents and
I am trying to set a custom class to an Iterator through the setInfoClass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.