Question

Nginx domain call root subdomain in multiple server

Posted April 22, 2021 132 views
Nginx

nginx config multiple server with ssl
my servername example.com read root from servername 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;
    } 
}

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.

×
Submit an Answer
1 answer

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