Question

Nginx domain call root subdomain in multiple server

  • Posted April 22, 2021
  • Nginx

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

Submit an 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