chaoslawful/lua-nginx-module — Issue #90: Set server_name through set_by_lua
Author: moodydeath
Created: 2012-03-06 14:12:11+00:00
State: open

Hi,

is there a way to set the server_name in a server-block with a lua script?

My config looks something like this:

```
server {
listen 80;
server_name foo.tld.com bar.tld.com;
root /srv/web/$host;
location {...}
}
server {
listen 80;
server_name ~^(www\.)?(?.+)$;
root /wrv/myapp;
location {...}
}
```

The thing is:

The first block will serve the 2 domains given in server_name and use the corresponding folder in /srv/web as root ... e.g. /srv/web/foo.tld.com ... to serve files.
The second server will "catch" all other domains pointing to the service and serve the default application (this is a wordpress multidomain installation here ;-) )

Now, this config works pretty well, but i would like to have it more dynamic. Like only to create a new folder e.g. /srv/web/new.page.tld and the first block will catch this domain from now on without having to edit nginx.conf and the server_name values.

Here comes my lua-attempt. I wrote a small script that would list the directory and return a space-separated list with the folders available in /srv/web ... e.g. it returns "foo.tld.com bar.tld.com mypage.mysite.com" .

I tried this:

```
set_by_lua $foo "[Here is the script that returns the string with folders]"
server_name $foo
```
The script works perfect when tested outsice, but unfortunatelly the server_name is set to nothing there...

Is there some lua-magic i can use? :-)