Apache Web Server & Virtual Host pada openSUSE : Bagian 2

Tutorial ini merupakan bagian kedua dari 3 tulisan. Untuk bagian pertama silakan baca disini. Tulisan ini dipresentasikan pada Kopdar #14 Komunitas openSUSE Indonesia hari Sabtu, 28 Februari yang baru lalu.

Setelah kita melakukan instalasi dan konfigurasi dasar Apache, langkah selanjutnya adalah melakukan aktivasi VirtualHost. Dalam tutorial ini saya akan menggunakan contoh 2 buah virtualhost, yaitu dengan nama dl.opensuse.or.id dan download.opensuse.or.id. Berikut adalah langkah-langkahnya :

  1. Bukalah folder /etc/apache2/vhosts.d
  2. Copy file vhost.template menjadi nama domain yang anda inginkan dan berekstension .conf, misalnya dalam contoh ini menjadi dl.opensuse.or.id.conf. Jika menginginkan lebih dari satu virtualhost sekaligus ingin memastikan virtualhost berjalan dengan baik, copy juga file tersebut dengan nama domain yang lain, misalnya download.opensuse.or.id.conf
  3. Buka file  dl.opensuse.or.id.conf dan lakukan perubahan hingga menjadi sebagai berikut :
    ########################################################################
    #
    # VirtualHost template
    # Note: to use the template, rename it to /etc/apache2/vhost.d/yourvhost.conf.
    # Files must have the .conf suffix to be loaded.
    #
    # See /usr/share/doc/packages/apache2/README.QUICKSTART for further hints
    # about virtual hosts.
    #
    # NameVirtualHost statements can be added to /etc/apache2/listen.conf.
    #
    # Almost any Apache directive may go into a VirtualHost container.
    # The first VirtualHost section is used for requests without a known
    # server name.
    #
    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerAdmin opensuse@opensuse.or.id
    ServerName dl.opensuse.or.id
    
    # DocumentRoot: The directory out of which you will serve your
    # documents. By default, all requests are taken from this directory, but
    # symbolic links and aliases may be used to point to other locations.
    DocumentRoot /srv/www/vhosts/dl.opensuse.or.id
    # if not specified, the global error log is used
    ErrorLog /var/log/apache2/dl.opensuse.or.id-error_log
    CustomLog /var/log/apache2/dl.opensuse.or.id-access_log combined
    
    # don't loose time with IP address lookups
    HostnameLookups Off
    
    # needed for named virtual hosts
    UseCanonicalName Off
    
    # configures the footer on server-generated documents
    ServerSignature On
    
    # Optionally, include *.conf files from /etc/apache2/conf.d/
    #
    # For example, to allow execution of PHP scripts:
    #
    # Include /etc/apache2/conf.d/mod_php4.conf
    #
    # or, to include all configuration snippets added by packages:
    # Include /etc/apache2/conf.d/*.conf
    
    # ScriptAlias: This controls which directories contain server scripts.
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the realname directory are treated as applications and
    # run by the server when requested rather than as documents sent to the client.
    # The same rules about trailing "/" apply to ScriptAlias directives as to
    # Alias.
    #
    #    ScriptAlias /cgi-bin/ "/srv/www/vhosts/dl.opensuse.or.id/cgi-bin/"
    
    # "/srv/www/cgi-bin" should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have one, and where ScriptAlias points to.
    #
    #    <Directory "/srv/www/vhosts/dummy-host.example.com/cgi-bin">
    #       AllowOverride None
    #       Options +ExecCGI -Includes
    #       Order allow,deny
    #       Allow from all
    #    </Directory>
    
    # UserDir: The name of the directory that is appended onto a user's home
    # directory if a ~user request is received.
    #
    # To disable it, simply remove userdir from the list of modules in APACHE_MODULES
    # in /etc/sysconfig/apache2.
    #
    <IfModule mod_userdir.c>
    # Note that the name of the user directory ("public_html") cannot simply be
    # changed here, since it is a compile time setting. The apache package
    # would have to be rebuilt. You could work around by deleting
    # /usr/sbin/suexec, but then all scripts from the directories would be
    # executed with the UID of the webserver.
    UserDir public_html
    # The actual configuration of the directory is in
    # /etc/apache2/mod_userdir.conf.
    Include /etc/apache2/mod_userdir.conf
    # You can, however, change the ~ if you find it awkward, by mapping e.g.
    # http://www.example.com/users/karl-heinz/ --> /home/karl-heinz/public_html/
    #AliasMatch ^/users/([a-zA-Z0-9-_.]*)/?(.*) /home/$1/public_html/$2
    </IfModule>
    
    #
    # This should be changed to whatever you set DocumentRoot to.
    #
    <Directory "/srv/www/vhosts/dl.opensuse.or.id">
    
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs-2.2/mod/core.html#options
    # for more information.
    #
    Options All
    #Indexes FollowSymLinks
    
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None
    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
    ########################################################################
    
  4. Perhatikan baik-baik, yang perlu diubah hanya beberapa point saja, misalnya untuk nama, document root dll
  5. Untuk document root, bedakan folder tujuan yang akan menjadi root folder masing dan tempatkan / masukkan file tertentu sebagai penanda. Contohnya, saya menambahkan file teks dengan nama ini lokasi dl.txt pada folder /srv/www/vhosts/dl.opensuse.or.id sehingga jika saya browsing akan menampilkan file tersebut. Hal yang sama saya lakukan dengan menempatkan file teks dengan nama ini lokasi download.txt pada folder /srv/www/vhosts/download.opensuse.or.id. Ini sekedar penanda saja, tidak mutlak perlu.
  6. Kalau sudah selesai, lakukan hal yang mirip dengan file download.opensuse.or.id.conf. Bedakan nama dan document root-nya.
  7. Setelah semuanya dilakukan, restart service Apache dengan mengetik perintah :
    service apache2 restart
  8. Edit file /etc/hosts dan tambahkan alamat dl.opensuse.or.id dan download.opensuse.or.id dengan merujuk pada IP yang ada. Ini fungsinya sebagai pengganti DNS untuk keperluan testing, tidak untuk keperluan nyata karena untuk penggunaan secara public, hal ini dilakukan melalui DNS Server dengan menambahkan address record yang bersesuaian
  9. Test dengan membuka http://dl.opensuse.or.id dan http://download.opensuse.or.id
  10. Salah satu kegagalan yang umum terjadi sewaktu melakukan setting virtualhost adalah “kelupaan” menambahkan prefix NameVirtualHost *:80 pada bagian atas konfigurasi. Tanpa prefix ini, semua virtualhost akan merujuk pada alamat yang sama

Silakan dicoba, semestinya kita sudah dapat mengakses alamat URL http://dl.opensuse.or.id dan http://download.opensuse.or.id

Popularity: 49% [?]

9 Responses to “ Apache Web Server & Virtual Host pada openSUSE : Bagian 2 ”

  1. [...] Berlanjut ke tutorial bagian 2 [...]

  2. Mas Vavai, bagaimana cara setting di virtualhost untuk mengakses phpmyadmin-nya???

  3. [...] Continued here: Apache Web Server & Virtual Host pada openSUSE : Bagian 2 [...]

  4. [...] tutorial dari Mas Vavai ( Apache Web Server & Virtual Host pada openSUSE : Bagian 1 dan Apache Web Server & Virtual Host pada openSUSE : Bagian 2 [...]

  5. tengqyu bnget pak vavai buat ilmunya,,,,jgn bosen2 sharing2 ilmu buat Qt2 yg bodoh ini,,,,

  6. Mas klo bkin vhost!
    apa harus bikin ip aliasing juga!

  7. @Ardi,

    Ya, tentu saja. IP Aliasing sebenarnya bisa digantikan dengan setup DNS Server.

  8. mas, saya coba seperti cara di tutorial, tapi kok malah jadi forbiden waktu diakses ya?
    padahal di dalamnya sudah ada index.php nya.

  9. I really like your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to design my own blog and would like to know where u got this from. kudos

Leave a Reply

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>