Question

Serving two different root folders from ngix

Hi, I’ve got a working server running nginx with the site information below

server { listen 80; listen [::]:80;

    root /var/www/app1/public;

    index index.php;

    server_name 12.23.456.789;

    location / {
    try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    }


    location ~ /\.ht {
    deny all;
    }

}

server { listen 8080; listen [::]:8080;

    root /var/www/app2/public;

    index index.php;

    server_name 12.23.456.789;

    location / {
    try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    }


    location ~ /\.ht {
    deny all;
    }

}

Unfortunately I can not manage the get the same working setup in DigitalOcean Droplet… Any ideas might might be the case or what am I missing? Just getting errors about conflicting server name

conflicting server name “12.23.456.789” on 0.0.0.0:80, ignored conflicting server name “12.23.456.789” on [::]:80, ignored conflicting server name “12.23.456.789” on 0.0.0.0:8080, ignored conflicting server name “12.23.456.789” on [::]:8080, ignored


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Find a fix (at least a temporary one). I’m using a floating ip as the other servername. Seems to work…

EDIT: The config you copy/pasted above should actually work. There must be duplicate copies of your config, basically a place where you are defining a server block with the same server_name and port twice.

Take a look at this tutorial for complete context on nginx config for multiple sites: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

nginx config would fail with the error conflicting server name if you have multiple server {} blocks with the same PORT and SERVER_NAME lines.

nginx config could be in files in /etc/nginx/sites-enabled/default or in /etc/nginx/conf.d - take a look and confirm that there are no places where you are defining the same port and server_name in two different server{} blocks.