1

I have the following Nginx configuration using regular expression server names, so I can easily add static sites without adding new configuration entries:

server {
        server_name ~^(?<domain>.+)$;
        root /home/static/sites/$domain;

        access_log /var/log/nginx/$domain-static-access.log;
        error_log /var/log/nginx/$domain-static-error.log;
}

This works fine for serving the site, and the access logs end up at e.g. /var/log/nginx/example.com-static-access.log as desired. But the error logs end up at /var/log/nginx/$domain-static-error.log. It does not interpolate the value of that regex capture.

Any idea how to fix that?

3
  • 1
    I'm not sure but this may help you Commented Jan 4, 2016 at 21:15
  • @EduardoEscobar Thank you! It claims that "error_log won't work with variables at all" so that would explain it… Commented Jan 4, 2016 at 21:16
  • @EduardoEscobar If you add that as an answer I'd be happy to accept it. Commented Jan 4, 2016 at 21:20

2 Answers 2

2

Only some nginx configuration directives support variables. Whether or not variables are supported by a particular configuration directive in a particular parameter is explicitly documented. E.g., the access_log directive description say:

The file path can contain variables (0.7.6+), but such logs have some constraints...

The error_log directive does not support variables at all, and accordingly its description doesn't say anything about variables support. Note that this is intentional: error logs are to log errors, including low-level ones like memory allocation errors, and error logging is designed to avoid operations which can fail.

In other words, error_log does not support variables and there are no plans to add such a support. Use some fixed name instead.

Sign up to request clarification or add additional context in comments.

Comments

1

Well then, take a look at this. Indeed, it seems to be that error_log path won't accept variables in nginx configuration file.

1 Comment

I accepted the later answer because it was more fleshed out – hope that's alright. Thank you so much again for helping me solve this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.