Question

Nginx domain call root subdomain in multiple server

nginx config multiple server with ssl my server_name example.com read root from server_name admin.example.com

code
server {
    listen      80;
    listen 433 ssl;
    ssl         on;
    ssl_certificate         /etc/ssl/certs/cert.pem;
    ssl_certificate_key     /etc/ssl/private/key.pem;
    server_name example.com www.example.com;
    root /var/www/html/example/dist;
    location / {
      try_files $uri $uri/ /index.html;
    } 
}

server {
    listen      80;
    listen 433 ssl;
    ssl         on;
    ssl_certificate         /etc/ssl/certs/cert.pem;
    ssl_certificate_key     /etc/ssl/private/key.pem;
    server_name admin.example.com www.admin.example.com;
    root /var/www/html/admin-example/dist;
    location / {
      try_files $uri $uri/ /index.html;
    } 
}

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.

Hi @uniicoth,

I’m not sure I understand the question exactly. Do you want to make your domain.com to read files from another folder like root /var/www/html/admin-example/dist?

If that’s the case, you can just the root of your website at /var/www/html/ just like

root /var/www/html/

And then using location blocks load anything you need to load from different directories.

Regards, KFSys