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.

I have a server which I want to hosts two web apps (one site and one webapp for instance) and a newbie with nginx (and webhosting).

I have:

  • a web server (accessible using http://server.name)
  • a main site address (main.site.name or www.main.site.name). Its content is on the server in /usr/share/nginx/www.main.site.name
  • a web app with a specific adress (subdomain.other.site). Its content is on the server in /usr/share/nginx/test

I configured my main site using this:

    server {
    server_name .main.site.name;
    root /usr/share/nginx/www.main.site.name;
    index index.html index.htm;
    location / {
        try_files $uri $uri/ /index.html;
    }
    location ~ \.php$ {    
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

I configured my wab app using this but it does not work:

    server {
        listen subdomain.other.site:80;
        server_name subdomain.other.site;

        root /usr/share/nginx/test;
        index index.html index.htm;
        location / {
            try_files $uri $uri/ /index.html;
        }
        location ~ \.csv$ {
            alias /usr/share/nginx/test/$uri;
        }
    }

This configuration always show me the index.html from the /usr/share/nginx/www.main.site.name

How can I rewrite my configuration to make this work ? Should I use rewrite directives, but how ?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

for default site:

server {
    listen 80 default_server;
    server_name  _;

    # ....
}

and then, for each specific, known site:

server {
    listen 80;
    server_name .main.site.name;

    # ....
}

server {
    listen 80;
    server_name subdomain.other.site;

    # ....
}
share|improve this answer
    
It does not work for subdomain.other.site: I get a 500 internal server error. Would I need a rewrite directive ? –  lauhub Jul 4 '13 at 21:10
    
is there anything useful in error log? –  Teftin Jul 4 '13 at 21:20
    
Well, after a good night the solution came to me: the problem is not with the nginx configuration, it is fine and works but only if the web redirection is correct. Using an A record type leads to error. Using a CNAME solves the problem. Sorry that I was not aware the difference was so important. –  lauhub Jul 5 '13 at 6:20

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.