Sebelum kita mulai, Anda harus mempunyai akses root agar bisa menambahkan nginx template WHMCS Rule. setelah anda login ke server dengan akses root, silahkan masuk ke folder /usr/local/vesta/data/templates/web/nginx/php-fpm
:
cd /usr/local/vesta/data/templates/web/nginx/php-fpm
Langkah berikutnya anda akan membuat 2 file. yang pertama untuk non SSL, yang kedua untuk SSL.
1. Template non SSL
Template non SSL menggunakan extensi tpl. Jadi untuk whmcs kita buat file dengan nama whmcs.tpl sebagai berikut (gunakan perintah nano whmcs.tpl
):
server { listen %ip%:%web_port%; server_name %domain_idn% %alias_idn%; # Hapus tanda pagar jika anda menghendaki redirect ke HTTPS # return 301 https://$server_name$request_uri; root %docroot%; index index.php index.html index.htm; access_log /var/log/nginx/domains/%domain%.log combined; access_log /var/log/nginx/domains/%domain%.bytes bytes; error_log /var/log/nginx/domains/%domain%.error.log error; location / { location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ { expires max; } location ~ [^/]\.php(/|$) { fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; if (!-f $document_root$fastcgi_script_name) { return 404; } fastcgi_pass %backend_lsnr%; fastcgi_index index.php; include /etc/nginx/fastcgi_params; } } error_page 403 /error/404.html; error_page 404 /error/404.html; error_page 500 502 503 504 /error/50x.html; location /error/ { alias %home%/%user%/web/%domain%/document_errors/; } location ~* "/\.(htaccess|htpasswd)$" { deny all; return 404; } location /vstats/ { alias %home%/%user%/web/%domain%/stats/; include %home%/%user%/conf/web/%domain%.auth; } # Announcements rewrite ^/announcements/([0-9]+)/[a-zA-Z0-9-]+.html$ /./announcements.php?id=$1 last; rewrite ^/announcements$ /./announcements.php last; # Downloads rewrite ^/downloads/([0-9]+)/([^/]*)$ /./downloads.php?action=displaycat&catid=$1 last; rewrite ^/downloads$ /./downloads.php last; # Knowledgebase rewrite ^/knowledgebase/([0-9]+)/[a-zA-Z0-9-]+.html$ /./knowledgebase.php?action=displayarticle&id=$1 last; rewrite ^/knowledgebase/([0-9]+)/([^/]*)$ /./knowledgebase.php?action=displaycat&catid=$1 last; rewrite ^/knowledgebase$ /./knowledgebase.php last; include /etc/nginx/conf.d/phpmyadmin.inc*; include /etc/nginx/conf.d/phppgadmin.inc*; include /etc/nginx/conf.d/webmail.inc*; include %home%/%user%/conf/web/nginx.%domain_idn%.conf*; }
kemudian save (untuk nano bisa gunakan Ctrl+o).
Langkah berikutnya untuk template SSL menggunakan extensi stpl. Jadi kita gunakan nama whmcs.stpl dengan isi file sebagai berikut:
server { listen %ip%:%web_ssl_port%; server_name %domain_idn% %alias_idn%; root %sdocroot%; index index.php index.html index.htm; access_log /var/log/nginx/domains/%domain%.log combined; access_log /var/log/nginx/domains/%domain%.bytes bytes; error_log /var/log/nginx/domains/%domain%.error.log error; ssl on; ssl_certificate %ssl_pem%; ssl_certificate_key %ssl_key%; location / { try_files $uri $uri/ /index.php; location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ { expires max; } location ~ [^/]\.php(/|$) { fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; if (!-f $document_root$fastcgi_script_name) { return 404; } fastcgi_pass %backend_lsnr%; fastcgi_index index.php; include /etc/nginx/fastcgi_params; } } error_page 403 /error/404.html; error_page 404 /error/404.html; error_page 500 502 503 504 /error/50x.html; location /error/ { alias %home%/%user%/web/%domain%/document_errors/; } location ~* "/\.(htaccess|htpasswd)$" { deny all; return 404; } location /vstats/ { alias %home%/%user%/web/%domain%/stats/; include %home%/%user%/conf/web/%domain%.auth; } # Announcements rewrite ^/announcements/([0-9]+)/[a-zA-Z0-9-]+.html$ /./announcements.php?id=$1 last; rewrite ^/announcements$ /./announcements.php last; # Downloads rewrite ^/downloads/([0-9]+)/([^/]*)$ /./downloads.php?action=displaycat&catid=$1 last; rewrite ^/downloads$ /./downloads.php last; # Knowledgebase rewrite ^/knowledgebase/([0-9]+)/[a-zA-Z0-9-]+.html$ /./knowledgebase.php?action=displayarticle&id=$1 last; rewrite ^/knowledgebase/([0-9]+)/([^/]*)$ /./knowledgebase.php?action=displaycat&catid=$1 last; rewrite ^/knowledgebase$ /./knowledgebase.php last; include /etc/nginx/conf.d/phpmyadmin.inc*; include /etc/nginx/conf.d/phppgadmin.inc*; include /etc/nginx/conf.d/webmail.inc*; include %home%/%user%/conf/web/snginx.%domain_idn%.conf*; }
kemudian save.
Agar bisa terdaftar di vesta, restart vesta dengan perintah service vesta restart
, kemudian silahkan cek di admin vesta. Kalau berhasil, harusnya di bagian edit web sudah tersedia template nginx untuk whmcs seperti gambar berikut:
Selamat mencoba, semoga bermanfaat.