0

For various reasons, we follow an internal DNS scheme where the internal test site for 'www.test.com' would be 'p.test-tst.com.local'. I won't go into the details why we ended up with the scheme we're using.

Now, I could add 'p.test-tst.com.local', 'p.test-tst.de.local', 'p.test-tst.co.uk.local' (and so on) to the Nginx configuration file for this specific test site. However, Isn't there a more flexible way of doing this? Could I somehow make Nginx accept 'p.test.tst.com.local', and have it to rewrite that internally to 'www.test.com' so that the website (running on Drupal) would think that the request came for 'www.test.com'?

One of the main reasons why this would be nice is that I then would not have to think about adding more logic to Drupal when it comes to language handling (setting a language for 'com.local').

sbrattla
  • 1,578
  • 4
  • 28
  • 52

2 Answers2

2

If i understood you currectly you need something like this:

map $http_host $name { hostnames; p.test.tst.com.local test.com; ... } ... server { ... location / { fastcgi_pass unix:/var/run/php5-fpm.sock include fastcgi_params fastcgi_param HTTP_HOST $name; }

This will set HTTP_HOST variable in $SERVER to test.com if actual requested hostname was p.test.tst.com.local. Drupal looks at $SERVER['HTTP_HOST'] value to determine a hostname. You can add other mappings to map {} so it's quite flexible.

Glueon
  • 3,664
  • 2
  • 24
  • 32
  • This means i still need to add 'p.test.tst.com.local' to server_name, doesn't it? No way to get around that one, is it? – sbrattla Oct 06 '14 at 10:40
  • 1
    If incoming request goes to the correct `server {}` without a server_name then no, you don't. In my example `map` just looks into HTTP HOST header (not into $server_name variable) and assigns a value to $name. Then you can use $name how you want. For example for setting HTTP_HOST variable. – Glueon Oct 06 '14 at 10:54
2

If you want your site to answer to these Hosts values then you have no choice, you must put them in the server_name directive (you could use wildcard or regex to make the conf shorter).

server {

    server_name www.test.com;
    include /path/to/server_names;

    [ ... ]

    location / {
        [ ... ]
        fastcgi_param HTTP_HOST "www.test.com";
    }

}

File /path/to/server_names :

server_name p.test-tst.co.uk.local;
server_name p.test-tst.de.local;
Xavier Lucas
  • 13,095
  • 2
  • 44
  • 50