Showing posts with label apache httpd. Show all posts
Showing posts with label apache httpd. Show all posts

Saturday, June 30, 2018

Setting Virtual Host di Apache

Apache adalah salah satu web server yang cukup banyak digunakan saat ini untuk melayani aplikasi berbasis web. Kali ini, saya ingin berbagi tentang cara mengatur virtual host di Apache. Karena masing-masing web server seperti nginx memiliki cara nya sendiri untuk setting virtual host. 

Pertama kita harus install apache di server kita dalam hal ini saya menggunakan ubuntu.

sudo apt-get update
sudo apt-get install apache2

Selanjutnya kita akan membuat direktori untuk aplikasi kita. Kita akan membuat direktori aplikasi di folder /var/www/.

sudo mkdir -p /var/www/web1.com/public_html
sudo mkdir -p /var/www/web2.com/public_html

Selanjutnya adalah membuat simple page untuk masing-masing virtual host.

nano /var/www/web1.com/public_html/index.html

<html>
  <head>
    <title>Welcome to Web1.com!</title>
  </head>
  <body>
    <h1>Success!  The web1.com virtual host is working!</h1>
  </body>
</html>

nano /var/www/web2.com/public_html/index.html

<html>
  <head>
    <title>Welcome to Web2.com!</title>
  </head>
  <body>
    <h1>Success!  The web2.com virtual host is working!</h1>
  </body>
</html>

Selanjutnya kita membuat virtual host config file.

sudo nano /etc/apache2/sites-available/web1.com.conf
<VirtualHost *:80>
    ServerAdmin admin@web1.com
    ServerName web1.com
    ServerAlias www.web1.com
    DocumentRoot /var/www/web1.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Untuk virtual host yang kedua

sudo nano /etc/apache2/sites-available/web2.com.conf
<VirtualHost *:80>
    ServerAdmin admin@web2.com
    ServerName web2.com
    ServerAlias www.web2.com
    DocumentRoot /var/www/web2.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable virtual host.

sudo a2ensite web1.com.conf
sudo a2ensite web2.com.conf

Restart service apache

sudo service apache2 restart

Sekarang kita sudah bisa mengakses kedua web, untuk menguji virtual host nya sudah berjalan atau belum.

Untuk virtual host yang kedua

Sekian informasi yang saya bagikan kali ini, Terimakasih.

Thursday, June 18, 2015

Apache httpd + Tomcat (mod_jk connector)

Sebuah aplikasi web biasanya ditempatkan di server aplikasi seperti Apache Tomcat. Application Server tidak dirancang untuk hardening security dan biasanya membutuhkan web server sebagai proxy antara request pengguna ke server aplikasi. Salah satu contoh dari web server adalah Apache2 (Apache HTTP Server).

ilustrasi arsitektur sistem

Untuk dapat menghubungkan antara web server (Apache HTTP Server) dengan application server (Apache Tomcat) kita perlu sebuah konektor yang bernama mod_jk.

Apache Tomcat dapat didownload dari http://tomcat.apache.org/download-70.cgi 

Apache HTTP Server dapat didownload dari http://httpd.apache.org/download.cgi 
mod_jk dapat didownload dari http://tomcat.apache.org/download-connectors.cgi

Setelah Apache2 dan Tomcat terinstal, siapkan mod_jk yang telah di download, dan di ekstrak.




copy mod_jk.so ke dalam folder modules di direktori instalasi Apache2.

Tambahkan konfigurasi ini ke file httpd.conf:
# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
# Update this path to match your conf directory location
JkWorkersFile C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\conf\workers.properties 

# Where to put jk logs
# Update this path to match your logs directory location
JkLogFile C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\logs\mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

# Send everything for context to worker ajp13
JkMount /application-web ajp13
JkMount /application-web/* ajp13

Berikutnya, buat file workers.properties dalam folder conf di direktori instalasi Tomcat 

Isi file workers.properties adalah sebagai berikut:

# Define 1 real worker named ajp13
worker.list=ajp13

# Set properties for worker named ajp13 to use ajp13 protocol,
# and run on port 8009
worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009
worker.ajp13.connection_pool_size=100
worker.ajp13.connection_pool_minsize=10
worker.ajp13.connection_pool_timeout=60
worker.ajp13.socket_keepalive=1
worker.ajp13.socket_timeout=300

Pastikan pada file server.xml pada folder config tomcat bagian berikut tidak ter-remark:
<connector port="8009" protocol="AJP/1.3" redirectport="8443">

Selanjutnya running Apache2 dan Tomcat. Akses url Apache2 + /application-web :
http://localhost:8080/application-web

Sekarang, semua permintaan pengguna akan diterima oleh Apache2 pertama dan kemudian diteruskan ke tomcat.

berikutnya, kita dapat mengkonfigurasi pengerasan keamanan pada Apache2, karena Apache2 adalah web server dan memiliki banyak fitur-fitur hardening security seperti SSL, anti-DOS, dll

Referensi : https://www3.ntu.edu.sg/home/ehchua/programming/howto/ApachePlusTomcat_HowTo.html