How To Whitelist IP for ModSecurity

If you want to whitelist ip from checked by modsecurity. These steps are applied to Linux Ubuntu OS.

  1. First, connect to the server via SSH.
  2. After that, create or open the ModSecurity file used for IP whitelisting.
  3. Then, add the following rule in a single line: SecRule REMOTE_ADDR "@ipMatch 103.10.145.0/24,192.168.0.2" "id:3,phase:1,t:none,log,pass,ctl:ruleRemoveById=33444"
    You have to replace `33444` with the rule ID and `103.10.145.0/24` with the IP addresses you want to whitelist. You can mention multiple addresses, separated by commas.
  4. Next step, check the Apache syntax, using this command: apache2ctl -t
  5. If the syntax check is successful, you can apply the new configuration by reloading the apache2: service apache2 reload

Cara Install dan konfigurasi Redis dan Memcached pada server Moodle

Salah satu cara agar performa server e-learning yang menggunakan moodle adalah dengan mengaktifkan cache. Aplikasi cache yang bisa digunakan pada server moodle diantaranya adalah Redis dan Memcache. Berikut adalah langkah-langkah menginstall redi dan memcache pada server dengan OS Ubuntu 22.04. Pada server tersebut php yang digunakan adalah php versi 7.4. Redis dan Memcache hanya akan digunakan secara lokal.

  1. Update terlebih dahulu katalog apt
    • apt update
  2. Install redis server dan memcached
    • apt install redis-server redis-tools memcached libmemcached-tools
  3. Selanjutnya konfigurasi redis apabila diperlukan, misalnya mengkonfigurasi password atau ip
    • Buka file konfigurasi redis
      • nano /etc/redis/redis.conf
    • Apabila ingin menambahkan password silahkan tambahkan baris berikut:
      • requirepass PASSWORD
    • Kemudian restart redis dengan perintah
      • systemctl restart redis-server
  4. Konfigurasi juga memcached
    • Buka file konfigurasi redis
      • nano /etc/memcached.conf
    • Apabila ingin mengubah ukuran memory menjadi 128 MB silahkan tambahkan baris berikut:
      • -m 128mb
    • Kemudian restart memcached dengan perintah
      • systemctl restart memcached
  5. Selanjutnya install konektor php dengan redis dan memcache
    • apt install php7.4-redis php7.4-memcached
  6. Untuk memeriksa apakah redis dan memcache sudah berjalan, gunakan perintah berikut
    • Memeriksa redis
      • ps aux | grep redis
      • redis-cli
      • 127.0.0.1:6379>auth PASSWORD
      • 127.0.0.1:6379>info server
      • 127.0.0.1:6379>exit
    • Memeriksa memcache
      • ps aux | grep memcached
      • echo stats | nc 127.0.0.1 11211
  7. Selanjutnya buka moodle, kemudian masuk ke halaman Site Administrator – Plugin
    • Pada bagian caching – cache stores, klik menu Memcached
    • Isikan 127.0.0.1:11211 pada field test-server, kemudian save changes
    • Kemudian kembali lagi ke bagian caching – cache stores, klik menu Redis
    • Isikan 127.0.0.1 pada field test server dan pada field test server password isikan password redis, kemudian save changes
    • Setelah halaman test redis dan memcached selesai dikonfigurasi, lakukan test performance melalui menu Caching – Test Performance
    • Pastikan pada halaman test performance, bagian redis dan memcached ada nilainya.
  8. Langkah berikutnya setelah test perfomance berjalan dengan baik, lakukan konfigurasi redis dan memcache.
    • Klik Caching – Configuration
    • Pada bagian memcached, klik add instances
      • Isikan nama pada store name, misalnya Memcached_1
      • Isikan ip server pada field servers atau path ke file sock memcached
      • Kemudian simpan
    • Kembali ke Caching – Configuration, pada bagian redis, klik add instances
      • Isikan nama pada store name, misalnya Redis_1
      • Isikan ip server pada field servers atau path ke file sock redis
      • Isikan juga password pada field password
      • Kemudian simpan

Langkah-langkah install dan konfigurasi redis dan memcache pada server moodle dengan os Ubuntu dan php versi 7.4 telah selesai. Selanjutnya anda dapat memonitor dan menyesuaikan konfigurasi agar server moodle dapat berjalan dengan optimal.

How to Increase the File Upload Size in Moodle Assignments

To increase file upload size in Moodle, you must change some parameters in web engine and moodle.

Configure php.ini

If you are using php-fpm, you can find file php.ini under /etc/php/{version}/fpm/php.ini. You have to change {version} based on PHP version you used. Example: /etc/php/7.4/fpm/php.ini.

$sudo nano /etc/php/7.4/fpm/php.ini

You have to change these parameters, upload_file_size and post_max_size. You also have to change max_execution_time to extend upload’s time. Example you can set value like this for upload max 50MB and increase execution time to 300 seconds.

upload_file_size = 50MB
post_max_size = 50MB
max_execution_time = 300

Restart php-fpm using this command: /etc/init.d/php7.4-fpm restart

Configure Web Engine

NginX

If you are using nginx, you can use the httpserver, or location block to edit client_max_body_size.

  • Changes to the http block affect all server blocks (virtual hosts).
  • Changes to the server block affect a particular site or application.
  • Changes to the location block affect a particular directory for uploads under a site
    or application.

In this example, we increase limit size to 50MB.

  1. Edit the /etc/nginx/nginx.conf file to increase the limit of the files to upload:
    • http: http { ... client_max_body_size 50M; }
    • server: server { ... client_max_body_size 50M; }
    • location: location /uploads { ... client_max_body_size 50M; }
  2. Save the file and restart the NGINX webserver to apply the changes:
    • systemd systemctl restart nginx
    • sysvinit service nginx restart

Apache2

If you are using apache2, you only have to restart apache2 using command: systemctl apache2 restart.

Change Moodle Settings

1. As an Administrator to ensure that courses created in the future will have the new Maximum upload size, go to Site Administration > Courses > Course default settings and scroll down to Files and Uploads section. Ensure that the Maximum upload size is set to a higher value example 50MB. Again, we recommend Site upload limit.

2. Then, to increase your File Submissions limit, and this is the crucial step, go to Site Administration > Plugins > Activity modules > Submission Plugins > File submissions. Here you can increase the Maximum submission size from its default to a higher value. We recommend Site upload limit but your requirements may differ.