Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to set the root based on what server the request is coming from. This is what i would like to accomplish in nginx. I took out stuff I thought was irrelevant.

server {
    listen 81;
    charset utf-8;
    expires -1;

    location / {
        location ~* \.(jpg|jpeg|rtf|json|png|gif|css|js|swf|flv|ico)$ {
            expires max;
            access_log off;
            log_not_found off;

            if (server_name = {
                root /folder1
            if (server_name = {
                root /folder2
            if (server_name = {
                root /folder3
        try_files $uri $uri/ @proxy;

How can I go about setting this up?

share|improve this question
up vote 1 down vote accepted

Why not just do something like..

root /srv/www/$http_host;

and change the directory structure to match:



share|improve this answer

Your Answer


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.