Saturday, October 5, 2019

Utilisasi Apache Server untuk Aplikasi Berbasis Web

Apache Server sudah menjadi bagian yang tidak bisa dipisahkan dari daur hidup aplikasi berbasis web. Bagi Web Developer, Apache Server adalah opsi yang selalu ada di antara daftar web server yang dapat dijadikan target deployment.

Salah satu cara cepat untuk deployment aplikasi berbasis web adalah dengan menjadikan Apache sebagai proxy ke aplikasi yang ingin di-deploy. Berikut beberapa snippet untuk dapat melakukannya.

Contoh NodeJs
  1. Install modul Apache mod_proxy, mod_proxy_http 
  2. buat Virtual host yang akan menjadi proxy ke port yang digunakan oleh nodejs
  3. Code Snippet-nya sbb:
    <virtualhost>
      ServerName sub.domain.com
      ServerAdmin webmaster@domain.com

      ProxyRequests off

      <proxy *>
        Order deny,allow
        Allow from all
      </proxy>

      <location />
        ProxyPass http://localhost:8100/
        ProxyPassReverse http://localhost:8100/
      </location>
    </virtualhost>

Contoh Python
  1. Jangan lupa untuk menginstall modul Apache mod_proxy, mod_proxy_http.
  2. Contoh di bawah ini adalah menggunakan proxy port 8000 di Apache server sementara port yang digunakan oleh aplikasi adalah 8080
    Listen 8000
    <VirtualHost *:8000>
        ServerAdmin user@domain.com

        ServerName app.domain.com
        ServerAlias app
        SSLEngine on


        # Jika menggunakan SSL certificate
        SSLCertificateFile /path/to/file.crt
        SSLCertificateKeyFile /path/to/file.id.key
        SSLCertificateChainFile /path/to/intermediate.crt
     
        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8080/
        ProxyPassReverse / http://127.0.0.1:8080/

        LogLevel debug
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

No comments:

Post a Comment