skip to Main Content

In my hostinger vps Ubuntu OS I have to host my ecommerce website (Nginx) along with that I gave to host the admin panel and seller panel website also, but I donno how to host those 2 seller and admin portal as subdomains of the main ecommerce app,

I have tried many ways but couldn’t make it successfully

I tired and host the main app successfully but when I go with the subdomain for example admin.ecommerce.com I still directed to ecommerce.com ( the main Domain)

2

Answers


  1. There should be multiple server sections in the nginx configuration file, and each server section should contain a different server_name and set the root directory to the corresponding file.

    Login or Signup to reply.
  2.         Here's a general outline of the steps you need to follow:
    
    Prepare your websites: Make sure your main ecommerce website and the admin panel and seller panel websites are ready to be served by Nginx. Each website should have its own root directory containing the necessary files (HTML, CSS, JavaScript, etc.).
    

    Configure DNS records: Set up DNS records for your main domain (ecommerce.com) and the subdomains (admin.ecommerce.com, seller.ecommerce.com). Ensure that these DNS records point to the IP address of your VPS.

    Create Nginx server blocks: You need to create separate server blocks for each website (main website and subdomains) in Nginx configuration directory. Here's an example of how you can configure server blocks for your main website and two subdomains:
    # Main website
    server {
        listen 80;
        server_name ecommerce.com www.ecommerce.com;
    
        root /var/www/ecommerce;
        index index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.html;
        }
    }
    
    # Admin panel subdomain
    server {
        listen 80;
        server_name admin.ecommerce.com;
    
        root /var/www/admin;
        index index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.html;
        }
    }
    
    # Seller panel subdomain
    server {
        listen 80;
        server_name seller.ecommerce.com;
    
        root /var/www/seller;
        index index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.html;
        }
    }
    

    Replace /var/www/ecommerce, /var/www/admin, and /var/www/seller with the actual paths to the root directories of your main website and subdomains.

    Reload Nginx: After creating the server blocks, reload Nginx to apply the changes:
    sudo systemctl reload nginx
    Upload website files: Upload your website files to the respective root directories (/var/www/ecommerce, /var/www/admin, /var/www/seller) on your VPS.

    Test: Visit your main website (ecommerce.com) and the subdomains (admin.ecommerce.com, seller.ecommerce.com) in a web browser to ensure they are accessible.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search