Note: this is no longer the recommended way of hosting PiSearch. See Hosting in Docker unless you have a good reason not to!
This is a quick setup guide for an instance of the PiSearch API directly on a bare metal server or VM.
It is hosted on Debian Linux (version 9/Stretch) using apache2 as a reverse proxy to pass requests on to Kestrel running as a service listening on port 5000.
apache2 and dotnet must be installed.
For other dependencies to set up, see Running the API.
adduser pisearch
mkdir /var/www/v2.api.pisearch.joshkeegan.co.uk
chown pisearch /var/www/v2.api.pisearch.joshkeegan.co.uk
a2enmod headers
a2enmod proxy
a2enmod proxy_http
Create a config file at /etc.apache2/sites-available/v2.api.pisearch.joshkeegan.co.uk.conf
containing:
<VirtualHost *:*>
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName v2.api.pisearch.joshkeegan.co.uk
ErrorLog ${APACHE_LOG_DIR}/pisearch-error.log
CustomLog ${APACHE_LOG_DIR}/pisearch-access.log common
</VirtualHost>
Symlink to it from sites-enabled
:
ln -s /etc/apache2/sites-available/v2.api.pisearch.joshkeegan.co.uk.conf /etc/apache2/sites-enabled/v2.api.pisearch.joshkeegan.co.uk.conf
Finally, in order to use the new modules and config, restart apache:
service apache2 restart
Locally, run make publish-api
to publish the api.
Upload the contents of StringSearch.Api/out
to /var/www/v2.api.pisearch.joshkeegan.co.uk
on the server.
Set any production config in appsettings.Production.json
.
To check you have set everything up correctly, you can run Kestrel from the terminal with dotnet StringSearch.Api.dll
, but for production it is better to use a service.
Configure the new service by creating /etc/systemd/system/pisearch-api.service
containing:
[Unit]
Description=PiSearch API
[Service]
WorkingDirectory=/var/www/v2.api.pisearch.joshkeegan.co.uk
ExecStart=/usr/bin/dotnet /var/www/v2.api.pisearch.joshkeegan.co.uk/StringSearch.Api.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=pisearch-api
User=pisearch
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
Then start the service & check its status:
service pisearch-api start
systemctl status pisearch-api.service