Dokumentasi untuk Lab Reverse Proxy with Nginx Centos 7
Instalasi & Konfigurasi:
Ketentuan:
# useradd wordpress # useradd prestashop # useradd nextcloud
Kemudian tambahkan host untuk domain kita dengan listen 172.0.0.1 untuk mengarahkan nginx ke apache
# vim /etc/hosts
# yum -y install httpd
Ubah agar apache listen pada 127.0.0.1 dan pada port 8080
# vim /etc/httpd/conf/httpd.conf
Disini kita merubah listen menjadi 127.0.0.1 agar apache tidak bisa diakses dari luar, karena webserver dan reverse proxy dalam 1 server yang sama dan kita merubah port menjadi 8080 agar tidak bentrok dengan nginx yang akan berjalan pada port 80
Tambahkan repo mariadb
# vim /etc/yum.repos.d/mariadb.repo
# MariaDB 10.1 CentOS repository # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.1/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
Simpan dan keluar, selanjut nya install mariadb
# yum -y install mariadb-server
Start dan enable MariaDB
# systemctl start mariadb # systemctl enable mariadb
Kemudian setup MariaDB
# mysql_secure_installation
* Enter current password for root (enter for none): Just press the Enter * Set root password? [Y/n]: Y * New password: Enter password * Re-enter new password: Repeat password * Remove anonymous users? [Y/n]: Y * Disallow root login remotely? [Y/n]: Y * Remove test database and access to it? [Y/n]: Y * Reload privilege tables now? [Y/n]: Y
Selanjutnya install php, karena disini kita akan menggunakan 3 php dengan versi berbeda sekaligus, maka kita akan menggunakan php-fpm dan kita akan mengubah setiap port default ketiga php aga bisa berjalan secara bersamaan diwaktu yang sama
Install repositori php remi
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
Lalu install php satu per satu
php 7.1
# yum install php71 php71-php-fpm php71-php-mysql php71-php-pdo php71-php-gd php71-php-mbstring php71-php-mcrypt php71-php-xml php71-php-zip php71-php-intl php71-php-process php71-php-apcu -y
php 7.2
# yum -y install php72 php72-php-fpm php72-php-pdo php72-php-mysqlnd php72-php-opcache php72-php-xml php72-php-gd php72-php-devel php72-php-mysql php72-php-intl php72-php-mbstring php72-php-bcmath php72-php-json php72-php-iconv php72-php-soap php72-php-zip php72-php-mcrypt
php 7.3
# yum -y install php73 php73-php-fpm php73-php-pdo php73-php-mysqlnd php73-php-opcache php73-php-xml php73-php-gd php73-php-devel php73-php-mysql php73-php-intl php73-php-mbstring php73-php-bcmath php73-php-json php73-php-iconv php73-php-soap php73-php-zip php73-php-mcrypt
Konfigurasi php71. , buka www.conf
# vim /etc/opt/remi/php71/php-fpm.d/www.conf
Lalu tambahkan user dan group prestashop setelah apache, disini kita membuat agar webserver dapat mengakses direktory user
; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. ; RPM: apache user chosen to provide access to the same directories as httpd user = apache user = prestashop ; RPM: Keep a group allowed to write in log dir. group = apache group = prestashop
Kemudian ubah listen port :9000 menjadi :9071
; Note: This value is mandatory. listen = 127.0.0.1:9071
Lakukan untuk kedua user lainnya juga, sesuaikan dengan task
Ubah settingan selinux dari enforcing menjadi permissive
# setenforce 0
Jalankan Service php
# systemctl start php71-php-fpm # systemctl enable php71-php-fpm # systemctl start php72-php-fpm # systemctl enable php72-php-fpm # systemctl start php73-php-fpm # systemctl enable php73-php-fpm
# yum -y install nginx
Start dan enable Nginx
# systemctl start nginx # systemctl enable nginx
Pertama kita harus mengubah userdir.conf agar apache dapat mengakses user direktory
# vim /etc/httpd/conf.d/userdir.conf
Ubah UserDir Disabled menjadi UserDir Enabled [nama user], jika lebih dari satu user maka tambahkan [nama user] setelah [nama user] sebelumnya. lihat gambar dibawah agar lebih jelas
Kemudian scrol kebawah, di bagian
<Directory "/home/*/public_html"> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS </Directory>
Hapus public_html, lihat gambar di bawah
Simpan dan keluar, lalu restart service apache
# systemctl restart httpd
Kemudian kita akan membuat virtualhost untuk masing-masing website
#1 Virtualhost untuk prestashop
# Vim /etc/httpd/cong.d/prestashop.conf
Kemudian isikan
<VirtualHost *:8080> ServerName prestashop.task.my.id ServerAdmin admin@task.my.id DocumentRoot /home/prestashop ErrorLog /home/prestashop/error.log CustomLog /home/prestashop/requests.log combined <FilesMatch \.php$> SetHandler "proxy:fcgi://127.0.0.1:9071" </FilesMatch> <Directory /home/prestashop> <IfModule mod_dir.c> DirectoryIndex index.php index.html index.htm </IfModule> AllowOverride all Order allow,deny Allow from all </Directory> </VirtualHost>
Disini saya menggunakan domain prestashop.task.my.id untuk website prestashop nantinya, silakan ubah dengan domain kalian dan jangan lupa untuk menambahkan A record
Kemudian perhatikan SetHandler “proxy:fcgi://127.0.0.1:9071” , disini kita mengarahkan setiap pemrosesan php ke php7.1, ingat tadi pada konfigurasi php7.1 kita mengubah listen port menjadi 9071
#2 Virtualhost untuk wordpress
<VirtualHost *:8080> ServerName wordpress.task.my.id ServerAdmin admin@task.my.id DocumentRoot /home/wordpress ErrorLog /home/wordpress/error.log CustomLog /home/wordpress/requests.log combined <FilesMatch \.php$> SetHandler "proxy:fcgi://127.0.0.1:9072" </FilesMatch> <Directory /home/wordpress> <IfModule mod_dir.c> DirectoryIndex index.php index.html index.htm </IfModule> AllowOverride all Order allow,deny Allow from all </Directory> </VirtualHost>
Disini kita sesuaikan juga user dan listen portnya menjadi :9072
#3 Virtualhost untuk nextcloud
<VirtualHost *:8080> ServerName nextcloud.task.my.id ServerAdmin admin@task.my.id DocumentRoot /home/nextcloud ErrorLog /home/nextcloud/error.log CustomLog /home/nextcloud/requests.log combined <FilesMatch \.php$> SetHandler "proxy:fcgi://127.0.0.1:9073" </FilesMatch> <Directory /home/nextcloud> <IfModule mod_dir.c> DirectoryIndex index.php index.html index.htm </IfModule> AllowOverride all Order allow,deny Allow from all </Directory> </VirtualHost>
Jika sudah semua cek apakah ada konfigurasi yang salah
# httpd -t
Restart apache
# systemctl restart httpd