Virtual Host

1 min read

kali ini akan bahas tentang virtual host. virtual host simpelnya adalah membuat host baru yang punya folder root sendiri, sehingga server akan tampak seperti punya banyak domain.

Nginx

$ sudo su
$ mkdir -p /var/www/stikom.com/html
$ chown -R www-data:www-data /var/www/stikom.com/html
$ touch /var/www/stikom.com/html/index.html
$ cd /var/www/stikom.com/html/
$ echo "<p>terima kasih</p>" >> index.html
$ cp /etc/nginx/sites-available/default.save /etc/nginx/sites-available/stikom.com
$ nano /etc/nginx/sites-available/stikom.com

dalam text editor

server {
        listen 80;
        listen [::]:80;

        root /var/www/stikom.com/html;
        index index.html index.htm index.php;

        server_name stikom.com www.stikom.com;

        location / {
                try_files $uri $uri/ =404;
        }
}

exit text editor

$ ln -s /etc/nginx/sites-available/stikom.com /etc/nginx/sites-enabled/
$ nano /etc/nginx/nginx.conf

hapus # pada server_names_hash_bucket_size dan restart nginx. tambah host

$ nano /etc/hosts
127.0.0.1	stikom.com www.stikom.com

Apache

$ sudo su
$ mkdir -p /var/www/stikombali.com/html
$ chown -R www-data:www-data /var/www/stikombali.com/html
$ touch /var/www/stikombali.com/html/index.html
$ cd /var/www/stikombali.com/html/
$ echo "<p>terima kasih</p>" >> index.html
$ cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/stikombali.conf
$ nano /etc/apache2/sites-available/stikombali.conf

dalam text editor

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

exit text editor

$ sudo a2ensite stikombali.conf

hapus # pada server_names_hash_bucket_size dan restart nginx. tambah host

$ nano /etc/hosts
127.0.0.1	stikombali.com www.stikombali.com

selesai.

Bima Sena

Leave a Reply

Your email address will not be published. Required fields are marked *