Skip to content

Configure Nginx Multisite

Updated: at 06:53 AMSuggest Changes
  1. Install nginx.

    apt install nginx
    
  2. Create dns record for domain and point to same host ip, here i will use hosts file.

    echo "127.0.0.1 satu.dama.zip dua.dama.zip" >> /etc/hosts
    
  3. Create directory for each website

    # 1st website
    mkdir /var/www/html/satu
    
    # 2nd website
    mkdir /var/www/html/dua
    
  4. Create simple html page for each website

    echo "ini site satu" > /var/www/html/satu.dama.id/index.html
    echo "ini site dua" > /var/www/html/dua.dama.id/index.html
    
  5. Create nginx conf for first website.

    vim /etc/nginx/sites-available/satu
    
    server {
      listen 80;
    
      server_name satu.dama.id; #Need to replace With Your Domain
    
      root /var/www/html/satu.dama.id/;
    }
    
  6. Create nginx conf for second website.

    vim /etc/nginx/sites-available/dua
    
    server {
      listen 80;
    
      server_name dua.dama.id; #Need to replace With Your Domain
    
      root /var/www/html/dua.dama.id/;
    }
    
  7. Nginx service doesnt import config file at /etc/nginx/site-available, but only imports config files at /etc/nginx/site-enabled, so we have to copy or we can easily create a link to the directory.

    ln -s /etc/nginx/sites-available/satu /etc/nginx/sites-enabled/
    ln -s /etc/nginx/sites-available/dua /etc/nginx/sites-enabled/
    
  8. Restart the service

    systemctl restart nginx
    
  9. Run a test to see if everything works

    $ curl satu.dama.id
    ini site satu
    $ curl dua.dama.id
    ini site dua
    

Previous Post
Proxmox - Setup Proxmox VE on Debian
Next Post
Bash Reverse Shell