A blog about doing things with computers

Blog | Archive | Twitter | Github | Rss

Nginx Gotchas - wildcard server names

24 Mar 2015 | nginx, webserver, http

This is a short post about a nginx gotcha that stumped me for a few minutes. tl;dr nginx servernames using wildcards can only occur if they are preceding a dot.

Lets suppose we have an nginx vhost like this:

upstream mydomain_upstream {
  server localhost:8080;

server {
  server_name *.apps.my.domain.com;
  proxy_redirect http:// $scheme://;
  proxy_set_header Host $host;

  location / {
    proxy_pass mydomain_upstream;


This proxies to localhost:8080, which could for instance be something like tomcat or jetty. Let’s suppose we want our vhost to also proxy for requests coming in at *-apps.my.domain.com. You might try something like this:

server {
  server_name *.apps.my.domain.com *-apps.my.domain.com;

However, this will not work, to quote the nginx docs:

A wildcard name may contain an asterisk only on the name’s start or end, and only on a dot border. The names “www.*.example.org” and “w*.example.org” are invalid.

Therefore, we need to use a regex instead, so in our example we can instead use:

server {
  server_name *.apps.my.domain.com ~.*-apps[.]my[.]domain[.]com;

Note that now we’ve converted the server_name to use a regex we need to escape the dots so they don’t revert to match any character.

Older · View Archive (11)

Creating a lexer for syntax highlighting with Pygments

In my last post I added a lot of Terraform code snippets. The syntax of .tf files is similar to JSON, except with less commas and built in functions. In writing the post I naively tried to use JSON syntax highlighting for my code snippets but this didn’t come out as I’d hoped. Unfortunately there didn’t appear to be a format that would syntax-highlight the configuration file in a nice way. Eventually I settled for using ‘console’ syntax highlighting which is quite plain and dull. It made me wonder how this was handled and how easy it would be to take care of this functionality myself. I quick bit of Github and Google surfing led me to Pygments which is how this is handled in my blog. I decided to have a go at creating a Terraform lexer. I thought I’d document some of my experience of this and give a quick run through of how its done.


Provisioning with Terraform Part 2

In my last post I covered the basics of provisioning a single EC2 instance with terraform. This time we’re going to go further and explore the provisioners and some other features. I’m doing some pretty funky things just to show the power of terraform. As you’ll see later there are other (better) ways.