Sumber : https://musaamin.web.id/cara-setting-nginx-ssl-sebagai-reverse-proxy-untuk-apache-di-ubuntu-18-04/
Cara Setting Nginx + SSL Sebagai Reverse Proxy untuk Apache di Ubuntu 18.04
Nginx dan Apache dapat digunakan secara bersamaan di mana Nginx bertindak sebagai reverse proxy yang menerima permintaan dari client dan meneruskannya ke web server lain seperti Apache, kemudian Apache mengirimkan kembali respon yang diminta oleh Nginx untuk dikirimkan ke client. Hal ini dilakukan agar kedua web server ini bisa saling menutupi kekurangan.
nginx:configuration file/etc/nginx/nginx.conf test issuccessful
Restart Nginx
1
2
systemctl restart nginx
systemctl status nginx
Verifikasi Nginx reverse proxy dengan mengakses http://web.defnex.com/info.php
PHP Information – Nginx Reverse Proxy
6.Install dan Konfigurasi mod_rpaf
Apache module mod_rpaf menulis ulang nilai dari REMOTE_ADDR, HTTPS, dan HTTP_PORT. Jika tanpa module ini maka yang terbaca di Apache log adalah IP dari Nginx bukan dari visitor.
Memasukkan konfigurasi module, RPAF_ProxyIPs diisi dengan IP_SERVER
1
2
3
4
5
6
7
8
<IfModule mod_rpaf.c>
RPAF_Enable On
RPAF_HeaderX-Real-Ip
RPAF_ProxyIPs178.128.212.251
RPAF_SetHostName On
RPAF_SetHTTPS On
RPAF_SetPort On
</IfModule>
Mengaktifkan module rpaf
1
a2enmod rpaf
Tes konfigurasi Apache
1
apachectl-t
Restart Apache
1
systemctl restart apache2
Browse http://web.defnex.com/info.php, cek REMOTE_ADDR, harus berisi Public IP address dari komputer visitor
PHP Information – REMOTE ADDR
7.Setting HTTPS
Install SSL Let’s Encrypt untuk mengaktifkan HTTPS
1
2
3
cd
add-apt-repository ppa:certbot/certbot
apt install python-certbot-nginx-y
Generate SSL untuk subdomain web.defnex.com yang berada di Nginx
1
certbot--nginx-dweb.defnex.com
Masukkan alamat email
1
Enter email address(used forurgent renewal andsecurity notices)(Enter'c'tocancel):hai@musaamin.web.id
Setujui ToS
1
2
3
Please read the Terms of Service at https://letsencrypt.org/documents/ LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory
---------------------------
(A)gree/(C)ancel:A
Persetujuan untuk dikirimi informasi mengenai Let’s Encrypt, bisa jawab Y atau N.
1
2
3
Would you be willing toshare your email address with the Electronic Frontier Foundation,afounding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'dlike tosend you email about our work encrypting the web,EFF news,campaigns,andways tosupport digital freedom.
---------------------------
(Y)es/(N)o:N
Sertifikat SSL dibuat, mengubah dan menambahkan konfigurasi virtual host untuk SSL.
1:No redirect-Make no further changes tothe webserver configuration.
2:Redirect-Make all requests redirect tosecure HTTPS access.Choose thisfornewsites,orifyou're confident your site works on HTTPS. You can undo this change by editing your web server'sconfiguration.
----------------------------------------
Select the appropriate number[1-2]then[enter](press'c'tocancel):2
Install SSL untuk web.defnex.com selesai
1
Congratulations!You have successfully enabled https://web.defnex.com
Sertifikat SSL hanya berlaku selama 90 hari, renew untuk memperbarui sertifikat SSL
1
cerbot renew
Browse https://web.defnex.com/info.php, cek $_SERVER[‘SERVER_PORT’] dan $_SERVER[‘HTTPS’]
PHP Information – HTTPS
8.Blokir Akses Langsung ke Apache
Blokir akses langsung ke Apache pada port 8080 dengan menggunakan iptables.