Make nginx config like apache2 virtualhosts
        Posted  
        
            by 
                user2104070
            
        on Server Fault
        
        See other posts from Server Fault
        
            or by user2104070
        
        
        
        Published on 2014-06-05T09:19:30Z
        Indexed on 
            2014/06/05
            9:28 UTC
        
        
        Read the original article
        Hit count: 260
        
I have web server with apache2 with many subdomains on it like, domain.com, abc.domain.com, def.domain.com etc. etc. Now I got a new nginx server and want to set it up like apache2, so to test I created configs (2 files in /etc/nginx/sites-available/ and link to them from sites-enabled/) as shown,
domain.config:
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        root /srv/www/;
        index index.html index.htm;
        # Make site accessible from http://localhost/
        server_name domain.com;
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
}
abc-domain config:
server {
        listen 80;
        listen [::]:80;
        root /srv/www/tmp1/;
        index index.html index.htm;
        # Make site accessible from http://localhost/
        server_name abc.domain.com;
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
}
but when I access with domain.com I am getting index.html from /var/www/tmp1 only. Is there something I'm doing wrong in the nginx config?
© Server Fault or respective owner