Difference between revisions of "Apache: Virtual Host 2"

From OnnoWiki
Jump to navigation Jump to search
(Created page with "==Install== sudo apt-get update sudo apt-get install apache2 ==Buat Directory== sudo mkdir -p /var/www/example.com/public_html sudo mkdir -p /var/www/test.com/public_ht...")
 
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==Install==
 
==Install==
  
  sudo apt-get update
+
  sudo apt update
  sudo apt-get install apache2
+
  sudo apt install apache2
  
 
==Buat Directory==
 
==Buat Directory==
  
  sudo mkdir -p /var/www/example.com/public_html
+
  sudo mkdir -p /var/www/html/webmirror/test.ac.id/
  sudo mkdir -p /var/www/test.com/public_html
+
  sudo mkdir -p /var/www/html/webmirror/coba.ac.id/
  
  sudo chown -R $USER:$USER /var/www/example.com/public_html
+
  sudo chown -Rf nobody: /var/www/html/webmirror/test.ac.id/
  sudo chown -R $USER:$USER /var/www/test.com/public_html
+
  sudo chown -Rf nobody: /var/www/html/webmirror/coba.ac.id/
  
  sudo chmod -R 755 /var/www
+
  sudo chmod -Rf 755 /var/www/html/webmirror/
 +
sudo chown -Rf nobody: /var/www/html/webmirror/
  
 
==Buat Demo Page==
 
==Buat Demo Page==
Line 18: Line 19:
 
Edit
 
Edit
  
  nano /var/www/example.com/public_html/index.html
+
  vi /var/www/html/webmirror/test.ac.id/index.html
  
 
Isi dengan
 
Isi dengan
Line 24: Line 25:
 
  <html>
 
  <html>
 
   <head>
 
   <head>
     <title>Welcome to Example.com!</title>
+
     <title>Welcome to test.ac.id!</title>
 
   </head>
 
   </head>
 
   <body>
 
   <body>
     <h1>Success!  The example.com virtual host is working!</h1>
+
     <h1>Success!  The test.ac.id virtual host is working!</h1>
 
   </body>
 
   </body>
 
  </html>
 
  </html>
Line 33: Line 34:
 
Copy
 
Copy
  
  cp /var/www/example.com/public_html/index.html /var/www/test.com/public_html/index.html
+
  cp /var/www/html/webmirror/test.ac.id/index.html /var/www/html/webmirror/coba.ac.id/index.html
  
 
Modify jika di perlukan
 
Modify jika di perlukan
  
  nano /var/www/test.com/public_html/index.html
+
  vi /var/www/html/webmirror/coba.ac.id/index.html
 
 
  
 
  <html>
 
  <html>
 
   <head>
 
   <head>
     <title>Welcome to Test.com!</title>
+
     <title>Welcome to coba.ac.id!</title>
 
   </head>
 
   </head>
   <body> <h1>Success!  The test.com virtual host is working!</h1>
+
   <body>
 +
    <h1>Success!  The coba.ac.id virtual host is working!</h1>
 
   </body>
 
   </body>
 
  </html>
 
  </html>
Line 52: Line 53:
 
Buat Contekan
 
Buat Contekan
  
  sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
+
  sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test.ac.id.conf
  
 
Edit
 
Edit
  
  sudo nano /etc/apache2/sites-available/example.com.conf
+
  sudo vi /etc/apache2/sites-available/test.ac.id.conf
  
 
Aslinya
 
Aslinya
Line 70: Line 71:
  
 
  <VirtualHost *:80>
 
  <VirtualHost *:80>
     ServerAdmin admin@example.com
+
     ServerAdmin admin@test.ac.id
     ServerName example.com
+
     ServerName test.ac.id
     ServerAlias www.example.com
+
     ServerAlias www.test.ac.id
     DocumentRoot /var/www/example.com/public_html
+
     DocumentRoot /var/www/html/webmirror/test.ac.id
 
     ErrorLog ${APACHE_LOG_DIR}/error.log
 
     ErrorLog ${APACHE_LOG_DIR}/error.log
 
     CustomLog ${APACHE_LOG_DIR}/access.log combined
 
     CustomLog ${APACHE_LOG_DIR}/access.log combined
Line 82: Line 83:
 
Edit
 
Edit
  
  sudo cp /etc/apache2/sites-available/example.com.conf /etc/apache2/sites-available/test.com.conf
+
  sudo cp /etc/apache2/sites-available/test.ac.id.conf /etc/apache2/sites-available/coba.ac.id.conf
  sudo nano /etc/apache2/sites-available/test.com.conf
+
  sudo vi /etc/apache2/sites-available/coba.ac.id.conf
  
 
Akan tampak
 
Akan tampak
  
 
  <VirtualHost *:80>
 
  <VirtualHost *:80>
     ServerAdmin admin@test.com
+
     ServerAdmin admin@coba.ac.id
     ServerName test.com
+
     ServerName coba.ac.id
     ServerAlias www.test.com
+
     ServerAlias www.coba.ac.id
     DocumentRoot /var/www/test.com/public_html
+
     DocumentRoot /var/www/html/webmirror/coba.ac.id
 
     ErrorLog ${APACHE_LOG_DIR}/error.log
 
     ErrorLog ${APACHE_LOG_DIR}/error.log
 
     CustomLog ${APACHE_LOG_DIR}/access.log combined
 
     CustomLog ${APACHE_LOG_DIR}/access.log combined
Line 100: Line 101:
 
Enable
 
Enable
  
  sudo a2ensite example.com.conf
+
  sudo a2ensite test.ac.id.conf
  sudo a2ensite test.com.conf
+
  sudo a2ensite coba.ac.id.conf
  
 
Disable
 
Disable
Line 111: Line 112:
 
  sudo systemctl restart apache2
 
  sudo systemctl restart apache2
 
  sudo service apache2 restart
 
  sudo service apache2 restart
 +
sudo service apache2 reload
  
 
==Client==
 
==Client==
Line 116: Line 118:
 
Edit
 
Edit
  
  sudo nano /etc/hosts
+
  sudo vi /etc/hosts
  
 
Isi dengan
 
Isi dengan
Line 122: Line 124:
 
  127.0.0.1  localhost
 
  127.0.0.1  localhost
 
  127.0.1.1  guest-desktop
 
  127.0.1.1  guest-desktop
  111.111.111.111 example.com
+
  111.111.111.111 test.ac.id
  111.111.111.111 test.com
+
  111.111.111.111 www.test.ac.id
 +
111.111.111.111 coba.ac.id
 +
111.111.111.111 www.coba.ac.id
 +
 
 +
Dimana
  
 +
* 111.111.111.111 IP address server virtual
  
 
==Pranala Menarik==
 
==Pranala Menarik==

Latest revision as of 10:49, 11 October 2018

Install

sudo apt update
sudo apt install apache2

Buat Directory

sudo mkdir -p /var/www/html/webmirror/test.ac.id/
sudo mkdir -p /var/www/html/webmirror/coba.ac.id/
sudo chown -Rf nobody: /var/www/html/webmirror/test.ac.id/
sudo chown -Rf nobody: /var/www/html/webmirror/coba.ac.id/
sudo chmod -Rf 755 /var/www/html/webmirror/
sudo chown -Rf nobody: /var/www/html/webmirror/

Buat Demo Page

Edit

vi /var/www/html/webmirror/test.ac.id/index.html

Isi dengan

<html>
  <head>
    <title>Welcome to test.ac.id!</title>
  </head>
  <body>

Success! The test.ac.id virtual host is working!

  </body>
</html>

Copy

cp /var/www/html/webmirror/test.ac.id/index.html /var/www/html/webmirror/coba.ac.id/index.html

Modify jika di perlukan

vi /var/www/html/webmirror/coba.ac.id/index.html
<html>
  <head>
    <title>Welcome to coba.ac.id!</title>
  </head>
  <body>

Success! The coba.ac.id virtual host is working!

  </body>
</html>

Buat Virtual Host

Buat Contekan

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test.ac.id.conf

Edit

sudo vi /etc/apache2/sites-available/test.ac.id.conf

Aslinya

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Untuk virtualhost

<VirtualHost *:80>
    ServerAdmin admin@test.ac.id
    ServerName test.ac.id
    ServerAlias www.test.ac.id
    DocumentRoot /var/www/html/webmirror/test.ac.id
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Konfigurasi Apache2

Edit

sudo cp /etc/apache2/sites-available/test.ac.id.conf /etc/apache2/sites-available/coba.ac.id.conf
sudo vi /etc/apache2/sites-available/coba.ac.id.conf

Akan tampak

<VirtualHost *:80>
    ServerAdmin admin@coba.ac.id
    ServerName coba.ac.id
    ServerAlias www.coba.ac.id
    DocumentRoot /var/www/html/webmirror/coba.ac.id
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable Virtual Host

Enable

sudo a2ensite test.ac.id.conf
sudo a2ensite coba.ac.id.conf

Disable

sudo a2dissite 000-default.conf

Restart

sudo systemctl restart apache2
sudo service apache2 restart
sudo service apache2 reload

Client

Edit

sudo vi /etc/hosts

Isi dengan

127.0.0.1   localhost
127.0.1.1   guest-desktop
111.111.111.111 test.ac.id
111.111.111.111 www.test.ac.id
111.111.111.111 coba.ac.id
111.111.111.111 www.coba.ac.id

Dimana

  • 111.111.111.111 IP address server virtual

Pranala Menarik