Report this

What is the reason for this report?

Nginx domain call root subdomain in multiple server

Posted on April 22, 2021

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;
    } 
}


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!

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.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.