1 # Deploying the Nominatim Python frontend
3 The Nominatim can be run as a Python-based web application. You have the
4 choice between [Falcon](https://falcon.readthedocs.io/en/stable/)
5 and [Starlette](https://www.starlette.io/) as the ASGI framework.
7 This section gives a quick overview on how to configure Nginx to server
8 Nominatim. Please refer to the documentation of
9 [Nginx](https://nginx.org/en/docs/) for background information on how to configure it.
12 Throughout this page, we assume that your Nominatim project directory is
13 located in `/srv/nominatim-project` and that you have installed Nominatim
14 using the default installation prefix `/usr/local`. If you have put it
15 somewhere else, you need to adjust the commands and configuration
18 We further assume that your web server runs as user `www-data`. Older
19 versions of CentOS may still use the user name `apache`. You also need
20 to adapt the instructions in this case.
22 ### Installing the required packages
24 The recommended way to deploy Python ASGI application is to run
25 the ASGI runner (uvicorn)[https://uvicorn.org/]
26 together with (gunicorn)[https://gunicorn.org/] HTTP server. We use
27 Falcon here as the web framework.
29 Create a virtual environment for the Python packages and install the necessary
33 sudo apt install virtualenv
34 virtualenv /srv/nominatim-venv
35 /srv/nominatim-venv/bin/pip install SQLAlchemy PyICU psycopg[binary]\
36 psycopg2-binary python-dotenv PyYAML falcon uvicorn gunicorn
39 ### Setting up Nominatim as a systemd job
41 Next you need to set up the application that serves Nominatim. This is
42 easiest done with a systemd job.
44 Create the following file `/etc/systemd/system/nominatim.service`:
48 Description=Nominatim running as a gunicorn application
50 Requires=nominatim.socket
54 Environment="PYTHONPATH=/usr/local/lib/nominatim/lib-python/"
57 WorkingDirectory=/srv/nominatim-project
58 ExecStart=/srv/nominatim-venv/bin/gunicorn -b unix:/run/nominatim.sock -w 14 -k uvicorn.workers.UvicornWorker nominatim.server.falcon.server:run_wsgi
59 ExecReload=/bin/kill -s HUP $MAINPID
60 StandardOutput=append:/ssd/nominatim/log/gunicorn.log
67 WantedBy=multi-user.target
70 Make the new service known to systemd and start it:
73 sudo systemctl daemon-reload
74 sudo systemctl enable nominatim
75 sudo systemctl start nominatim
78 This sets the service up, so that Nominatim is automatically started
83 To make the service available to the world, you need to proxy it through
84 nginx. Add the following definition to the default configuration:
87 upstream nominatim_service {
88 server unix:/run/nominatim.sock fail_timeout=0;
99 proxy_set_header Host $http_host;
100 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
101 proxy_set_header X-Forwarded-Proto $scheme;
103 proxy_pass http://nominatim_service;
111 sudo systemctl reload nginx
114 and you should be able to see the status of your server under
115 `http://localhost/status`.