Deploy
======

There are several options for sanic deployment:

* Standalone server
* Running a pool of backend servers behind of nginx, HAProxy or other reverse proxy server

Every method has own benefits and disadvantages.

Running sanic servers behind nginx makes several advantages:

* At first, nginx is the perfect frontend server. It may prevent many attacks based on malformed http protocol etc.
* Second, running several sanic instances behind nginx allows to utilize all CPU cores.
* Third, nginx serves static files much faster than built-in sanic static file support.

But this way requires more complex configuration.

Template configuration files for nginx are presented below.
For more information, you can visit `sanic`_.

.. _sanic: https://sanic.readthedocs.io/en/latest/sanic/deploying.html

Configuration file for nginx
----------------------------

.. literalinclude:: ../../../deploy/nginx_streams.conf

Configuration file for systemd
------------------------------
Config should be located in directory /etc/systemd/system/

.. literalinclude:: ../../../deploy/systemd-luna-streams@.service

Start 2 instances on ports 5031, 5032:

.. code-block:: bash

    sudo systemctl start luna-streams\@{5161..5162}.service
