Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In order to not pass garbage to the back-end, I have a strict regex for a location directive. It looks like this:

location ^~ "/(some|stuff|more|bar|etc(-testing)?)/[a-zA-Z0-9]+/...(more|restrict).ext {
    # other directives
}

I would like to fold the line at 80 chars, is there a way to split up the configuration? The following results in a syntax error, but is something I am looking for:

location ^~ "/(some|stuff|more|bar|etc(-testing)?)/[a-zA-Z0-9]+/"\
            "...(more|restrict).ext" {
# results in a literal newline (%0A) being accepted
location ^~ "/(some|stuff|more|bar|etc(-testing)?)/[a-zA-Z0-9]+/
...(more|restrict).ext" {

I could not find hints in the documentation (http://wiki.nginx.org/ConfigNotation nor http://wiki.nginx.org/HttpCoreModule#location mention anything about folding lines)

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I don't think you can do this.

nginx treats all whitespace equally, so even if you tried to split your string like that, and nginx could parse it the way you intended, you would wind up with a regex with a bunch of whitespace in it, which I'm sure isn't what you want. If nginx couldn't parse it, which is more likely, you'd just get a syntax error.

You're just going to have to live with a few long lines, or make less complex regular expressions.

share|improve this answer
    
Well, if there cannot be leading spaces, I can live with that. But a newline seems to be interpreted literally as well. –  Lekensteyn Feb 2 at 9:20
    
It really is not the end of the world. :) –  Michael Hampton Feb 2 at 15:48
    
For now I am stuck with a location ".../[a-zA-Z0-9_...-]+$" pattern followed by another location ~ "\.pkg\.tar\.xz$" inside. Thanks for your answer, hopefully some day a better answer shows up ;) –  Lekensteyn Feb 2 at 20:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.