-
Notifications
You must be signed in to change notification settings - Fork 93
Deploy ngrest under Apache2 Web Server
Deploying ngrest under Apache2 Web Server is intended to use ngrest in production. Simple http server shipped with ngrest is suitable for development purposes and for very small deployment only.
To deploy ngrest under Apache2 you need to complete few steps.
sudo apt-get install libapr1-dev apache2-dev
touch ~/.ngrest/ngrest/CMakeLists.txt; make -C ~/.ngrest/ngrest-build
ls ~/.ngrest/ngrest-build/deploy/share/ngrest/modules/apache2/mod_ngrest.so
You should see full path to ngrest module, not the "No such file or directory" error:
/home/user/.ngrest/ngrest-build/deploy/share/ngrest/modules/apache2/mod_ngrest.so
sudo cp ~/.ngrest/ngrest/modules/apache2/conf/ngrest.* /etc/apache2/mods-available/
Edit /etc/apache2/mods-available/ngrest.load
setting correct ngrest module location, e.g. replace YOUR_USERNAME
with your username, for example:
LoadModule ngrest_module /home/user/.ngrest/ngrest-build/deploy/share/ngrest/modules/apache2/mod_ngrest.so
Edit /etc/apache2/mods-available/ngrest.conf
and set path where your ngrest services is stored, for example:
<IfModule mod_ngrest.c>
# path to deploy ngrest services from
ServicesPath /home/user/.ngrest/ngrest-build/deploy/share/ngrest/services
# optional path to deploy ngrest filters from, if not set, no filters get deployed
#FiltersPath /home/user/.ngrest/ngrest-build/deploy/share/ngrest/filters
# location regex on which ngrest is bound.
# this will bind /ngrest and /echo locations
<Location ~ "/ngrest">
SetHandler ngrest
</Location>
</IfModule>
Also you must edit Location
directive setting regex to all your bound ngrest service resource paths.
For example, if your service is declared in root namespace myorg
, myorg.calc.Calculator
with default location:
namespace myorg {
namespace calc {
class Calculator: public ngrest::Service
...
}
}
Resource paths occupied with this service will be /myorg/calc/Calculator
and all of your services are in myorg
namespace, you must edit location like that:
<Location "/myorg">
If you change resource path with *location: ...
metacomment you must edit <Location ...
as well.
If you're using two root namespaces, myorg1
and myorg2
you can change location like that:
<Location ~ "/(myorg1|myorg2)">
In this case when you access the /myorg1/....
or /myorg2/....
ngrest module will activated with Apache2 and you can access your service.
sudo a2enmod ngrest
sudo service apache2 restart
To test if module loaded and work you must access one of your services. If your ngrest.conf
as in example you can access ngrest services tester with this URL: http://localhost/ngrest/services