0

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 ?

1 Answer 1

1

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;

    # ....
}
3
  • It does not work for subdomain.other.site: I get a 500 internal server error. Would I need a rewrite directive ?
    – lauhub
    Jul 4, 2013 at 21:10
  • is there anything useful in error log?
    – Teftin
    Jul 4, 2013 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, 2013 at 6:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .