Friday, October 11, 2024

Cache as a web service


This example shows Apache as the front-end (or "reverse proxy") for cache server - it's assumed you've completed it first. Three steps to setting up Apache quickly:
  1. Enable FastCGI proxy used to communicate with Gliimly services - this is one time only:
    • If you use Ubuntu and similar:
      sudo a2enmod proxy
      sudo a2enmod proxy_fcgi

    • If you use Fedora and similar:
      sudo vi /etc/httpd/conf/httpd.conf

      and if you use OpenSUSE:
      sudo vi /etc/httpd/conf/httpd.conf

      Add the following at the end of httpd.conf:
      LoadModule proxy_module modules/mod_proxy.so
      LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

  2. Edit Apache configuration file:
    • If you use Debian (such as Ubuntu):
      sudo vi /etc/apache2/apache2.conf

    • If you use Fedora (such as RedHat), Archlinux:
      sudo vi /etc/httpd/conf/httpd.conf

    • If you use OpenSUSE:
      sudo vi /etc/apache2/httpd.conf

    Add this to the end of the configuration file - note "index" is the application name you created in the above example:
    ProxyPass "/index/" unix:///var/lib/gg/index/sock/sock|fcgi://localhost/index

  3. Restart Apache.
    • On Debian systems (like Ubuntu) or OpenSUSE:
      sudo systemctl restart apache2

    • On Fedora systems (like RedHat) and Arch Linux:
      sudo systemctl restart httpd

- Test web service

Now you can call your web service, from the web. In this case it's probably a local server (127.0.0.1) if you're doing this on your own computer. The URLs would be, for example to add, query and delete a key/value pair:
http://127.0.0.1/index/srv/op=add/key=1/data=d_1

http://127.0.0.1/index/srv/op=query/key=1

http://127.0.0.1/index/srv/op=delete/key=1

Note the URL request structure: first comes the application path ("/index") followed by request path ("/srv") followed by URL parameters (such as "/op=add/key=1/data=d_1"). The result in web browser are messages informing you that the key was added, queried or deleted.