1 # Deploying the Nominatim Python frontend
3 The Nominatim can be run as a Python-based
4 [ASGI web application](https://asgi.readthedocs.io/en/latest/). You have the
5 choice between [Falcon](https://falcon.readthedocs.io/en/stable/)
6 and [Starlette](https://www.starlette.io/) as the ASGI framework.
8 This section gives a quick overview on how to configure Nginx to serve
9 Nominatim. Please refer to the documentation of
10 [Nginx](https://nginx.org/en/docs/) for background information on how
14 Throughout this page, we assume your Nominatim project directory is
15 located in `/srv/nominatim-project` and you have installed Nominatim
16 using the default installation prefix `/usr/local`. If you have put it
17 somewhere else, you need to adjust the commands and configuration
20 We further assume that your web server runs as user `www-data`. Older
21 versions of CentOS may still use the user name `apache`. You also need
22 to adapt the instructions in this case.
24 ### Installing the required packages
26 The recommended way to deploy a Python ASGI application is to run
27 the ASGI runner [uvicorn](https://uvicorn.org/)
28 together with [gunicorn](https://gunicorn.org/) HTTP server. We use
29 Falcon here as the web framework.
31 Create a virtual environment for the Python packages and install the necessary
35 sudo apt install virtualenv
36 virtualenv /srv/nominatim-venv
37 /srv/nominatim-venv/bin/pip install SQLAlchemy PyICU psycopg[binary] \
38 psycopg2-binary python-dotenv PyYAML falcon uvicorn gunicorn
41 ### Setting up Nominatim as a systemd job
43 Next you need to set up the service that runs the Nominatim frontend. This is
44 easiest done with a systemd job.
46 Create the following file `/etc/systemd/system/nominatim.service`:
50 Description=Nominatim running as a gunicorn application
52 Requires=nominatim.socket
56 Environment="PYTHONPATH=/usr/local/lib/nominatim/lib-python/"
59 WorkingDirectory=/srv/nominatim-project
60 ExecStart=/srv/nominatim-venv/bin/gunicorn -b unix:/run/nominatim.sock -w 4 -k uvicorn.workers.UvicornWorker nominatim.server.falcon.server:run_wsgi
61 ExecReload=/bin/kill -s HUP $MAINPID
62 StandardOutput=append:/var/log/gunicorn-nominatim.log
69 WantedBy=multi-user.target
72 This sets up gunicorn with 4 workers (`-w 4` in ExecStart). Each worker runs
73 its own Python process using
74 [`NOMINATIM_API_POOL_SIZE`](../customize/Settings.md#nominatim_api_pool_size)
75 connections to the database to serve requests in parallel.
77 Make the new service known to systemd and start it:
80 sudo systemctl daemon-reload
81 sudo systemctl enable nominatim
82 sudo systemctl start nominatim
85 This sets the service up, so that Nominatim is automatically started
90 To make the service available to the world, you need to proxy it through
91 nginx. Add the following definition to the default configuration:
94 upstream nominatim_service {
95 server unix:/run/nominatim.sock fail_timeout=0;
106 proxy_set_header Host $http_host;
107 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
108 proxy_set_header X-Forwarded-Proto $scheme;
110 proxy_pass http://nominatim_service;
118 sudo systemctl reload nginx
121 and you should be able to see the status of your server under
122 `http://localhost/status`.