-
-
Notifications
You must be signed in to change notification settings - Fork 713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update documentation for new Python frontend #3178
Changes from 16 commits
d3372e6
6533af6
e672de0
75513a2
399b045
309ac46
558c42e
a987f22
386b4c8
f917fa6
ef1b52e
3bb27fb
2c24ba6
6e5f595
4e2683f
3794080
cafd8e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Deploying the Nominatim Python frontend | ||
|
||
The Nominatim can be run as a Python-based web application. You have the | ||
choice between [Falcon](https://falcon.readthedocs.io/en/stable/) | ||
and [Starlette](https://www.starlette.io/) as the ASGI framework. | ||
|
||
This section gives a quick overview on how to configure Nginx to server | ||
Nominatim. Please refer to the documentation of | ||
[Nginx](https://nginx.org/en/docs/) for background information on how to configure it. | ||
|
||
!!! Note | ||
Throughout this page, we assume that your Nominatim project directory is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "that" in this and next line can be removed |
||
located in `/srv/nominatim-project` and that you have installed Nominatim | ||
using the default installation prefix `/usr/local`. If you have put it | ||
somewhere else, you need to adjust the commands and configuration | ||
accordingly. | ||
|
||
We further assume that your web server runs as user `www-data`. Older | ||
versions of CentOS may still use the user name `apache`. You also need | ||
to adapt the instructions in this case. | ||
|
||
### Installing the required packages | ||
|
||
The recommended way to deploy Python ASGI application is to run | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deploy the |
||
the ASGI runner (uvicorn)[https://uvicorn.org/] | ||
together with (gunicorn)[https://gunicorn.org/] HTTP server. We use | ||
Falcon here as the web framework. | ||
|
||
Create a virtual environment for the Python packages and install the necessary | ||
dependencies: | ||
|
||
``` sh | ||
sudo apt install virtualenv | ||
virtualenv /srv/nominatim-venv | ||
/srv/nominatim-venv/bin/pip install SQLAlchemy PyICU psycopg[binary]\ | ||
psycopg2-binary python-dotenv PyYAML falcon uvicorn gunicorn | ||
``` | ||
|
||
### Setting up Nominatim as a systemd job | ||
|
||
Next you need to set up the application that serves Nominatim. This is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. section starts with "set up the application" but ends "this sets the service up". I think it should be service |
||
easiest done with a systemd job. | ||
|
||
Create the following file `/etc/systemd/system/nominatim.service`: | ||
|
||
``` systemd | ||
[Unit] | ||
Description=Nominatim running as a gunicorn application | ||
After=network.target | ||
Requires=nominatim.socket | ||
|
||
[Service] | ||
Type=simple | ||
Environment="PYTHONPATH=/usr/local/lib/nominatim/lib-python/" | ||
User=www-data | ||
Group=www-data | ||
WorkingDirectory=/srv/nominatim-project | ||
ExecStart=/srv/nominatim-venv/bin/gunicorn -b unix:/run/nominatim.sock -w 14 -k uvicorn.workers.UvicornWorker nominatim.server.falcon.server:run_wsgi | ||
ExecReload=/bin/kill -s HUP $MAINPID | ||
StandardOutput=append:/ssd/nominatim/log/gunicorn.log | ||
StandardError=inherit | ||
PrivateTmp=true | ||
TimeoutStopSec=5 | ||
KillMode=mixed | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
``` | ||
|
||
Make the new service known to systemd and start it: | ||
|
||
``` sh | ||
sudo systemctl daemon-reload | ||
sudo systemctl enable nominatim | ||
sudo systemctl start nominatim | ||
``` | ||
|
||
This sets the service up, so that Nominatim is automatically started | ||
on reboot. | ||
|
||
### Configuring nginx | ||
|
||
To make the service available to the world, you need to proxy it through | ||
nginx. Add the following definition to the default configuration: | ||
|
||
``` nginx | ||
upstream nominatim_service { | ||
server unix:/run/nominatim.sock fail_timeout=0; | ||
} | ||
|
||
server { | ||
listen 80; | ||
listen [::]:80; | ||
|
||
root /var/www/html; | ||
index /search; | ||
|
||
location / { | ||
proxy_set_header Host $http_host; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
proxy_redirect off; | ||
proxy_pass http://nominatim_service; | ||
} | ||
} | ||
``` | ||
|
||
Reload nginx with | ||
|
||
``` | ||
sudo systemctl reload nginx | ||
``` | ||
|
||
and you should be able to see the status of your server under | ||
`http://localhost/status`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,26 +254,70 @@ successfully. | |
nominatim admin --check-database | ||
``` | ||
|
||
Now you can try out your installation by running: | ||
Now you can try out your installation by executing a simple query on the | ||
command line: | ||
|
||
``` sh | ||
nominatim search --query Berlin | ||
``` | ||
|
||
or, when you have a reverse-only installation: | ||
|
||
``` sh | ||
nominatim reverse --lat 51 --lon 45 | ||
``` | ||
|
||
If you want to run Nominatim as a service, you need to make a choice between | ||
running the traditional PHP frontend or the new experimental Python frontend. | ||
Make sure you have installed the right packages as per | ||
[Installation](Installation.md#software). | ||
|
||
#### Testing the PHP frontend | ||
|
||
You can run a small test server with the PHP frontend like this: | ||
|
||
```sh | ||
nominatim serve | ||
``` | ||
|
||
This runs a small test server normally used for development. You can use it | ||
to verify that your installation is working. Go to | ||
`http://localhost:8088/status.php` and you should see the message `OK`. | ||
You can also run a search query, e.g. `http://localhost:8088/search.php?q=Berlin`. | ||
Go to `http://localhost:8088/status.php` and you should see the message `OK`. | ||
You can also run a search query, e.g. `http://localhost:8088/search.php?q=Berlin` | ||
or, for reverse-only installations a reverse query, | ||
e.g. `http://localhost:8088/reverse.php?lat=27.1750090510034&lon=78.04209025`. | ||
|
||
Do not use this test server in production. | ||
To run Nominatim via webservers like Apache or nginx, please continue reading | ||
[Deploy the PHP frontend](Deployment-PHP.md). | ||
|
||
#### Testing the Python frontend | ||
|
||
To run the test server against the Python frontend, you must choose a | ||
web framework to use, either starlette or falcon. Make sure the appropriate | ||
packages are installed. Then run | ||
|
||
``` sh | ||
nominatim serve --engine falcon | ||
``` | ||
|
||
or | ||
|
||
``` sh | ||
nominatim serve --engine starlette | ||
``` | ||
|
||
Go to `http://localhost:8088/status.php` and you should see the message `OK`. | ||
You can also run a search query, e.g. `http://localhost:8088/search.php?q=Berlin` | ||
or, for reverse-only installations a reverse query, | ||
e.g. `http://localhost:8088/reverse.php?lat=27.1750090510034&lon=78.04209025`. | ||
|
||
Note that search query is not supported for reverse-only imports. You can run a | ||
reverse query, e.g. `http://localhost:8088/reverse.php?lat=27.1750090510034&lon=78.04209025`. | ||
Do not use this test server in production. | ||
To run Nominatim via webservers like Apache or nginx, please continue reading | ||
[Deploy the Python frontend](Deployment-Python.md). | ||
|
||
To run Nominatim via webservers like Apache or nginx, please read the | ||
[Deployment chapter](Deployment.md). | ||
|
||
## Adding search through category phrases | ||
## Enabling search by category phrases | ||
|
||
If you want to be able to search for places by their type through | ||
If you want to be able to search for places by their type using | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd skip the "If you want" |
||
[special phrases](https://wiki.openstreetmap.org/wiki/Nominatim/Special_Phrases) | ||
you also need to import these key phrases like this: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,18 @@ | |
|
||
Show all details about a single place saved in the database. | ||
|
||
This API endpoint is meant for visual inspection of the data in the database | ||
and is meant for use with [Nominatim-UI](https://github.com/osm-search/nominatim-ui/). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Second "is meant" can be removed |
||
The parameters of the endpoint and the output may change occasionally between | ||
versions of Nominatim. Do not rely on the output in scripts or applications. | ||
|
||
|
||
!!! warning | ||
The details page exists for debugging only. You may not use it in scripts | ||
or to automatically query details about a result. | ||
The details endpoint at https://nominatim.openstreetmap.org | ||
may not used in scripts or bots at all. | ||
See [Nominatim Usage Policy](https://operations.osmfoundation.org/policies/nominatim/). | ||
|
||
|
||
## Parameters | ||
|
||
The details API supports the following two request formats: | ||
|
||
|
@@ -35,59 +40,90 @@ for a place is different between Nominatim installation (servers) and | |
changes when data gets reimported. Therefore it cannot be used as | ||
a permanent id and shouldn't be used in bug reports. | ||
|
||
!!! danger "Deprecation warning" | ||
The API can also be used with the URL | ||
`https://nominatim.openstreetmap.org/details.php`. This is now deprecated | ||
and will be removed in future versions. | ||
|
||
|
||
Additional optional parameters are explained below. | ||
## Parameters | ||
|
||
This section lists additional optional parameters. | ||
|
||
### Output format | ||
|
||
* `json_callback=<string>` | ||
| Parameter | Value | Default | | ||
|-----------| ----- | ------- | | ||
| json_callback | function name | _unset_ | | ||
|
||
Wrap JSON output in a callback function (JSONP) i.e. `<string>(<json>)`. | ||
When given, then JSON output will be wrapped in a callback function with | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "When set" might work to avoid using "given" twice |
||
the given name. See [JSONP](https://en.wikipedia.org/wiki/JSONP) for more | ||
information. | ||
|
||
* `pretty=[0|1]` | ||
| Parameter | Value | Default | | ||
|-----------| ----- | ------- | | ||
| pretty | 0 or 1 | 0 | | ||
|
||
Add indentation to make it more human-readable. (Default: 0) | ||
`[PHP-only]` Add indentation to the output to make it more human-readable. | ||
|
||
|
||
### Output details | ||
|
||
* `addressdetails=[0|1]` | ||
| Parameter | Value | Default | | ||
|-----------| ----- | ------- | | ||
| addressdetails | 0 or 1 | 0 | | ||
|
||
Include a breakdown of the address into elements. (Default: 0) | ||
When set to 1, include a breakdown of the address into elements. | ||
|
||
* `keywords=[0|1]` | ||
| Parameter | Value | Default | | ||
|-----------| ----- | ------- | | ||
| keywords | 0 or 1 | 0 | | ||
|
||
Include a list of name keywords and address keywords (word ids). (Default: 0) | ||
When set to 1, include a list of name keywords and address keywords | ||
in the result. | ||
|
||
* `linkedplaces=[0|1]` | ||
| Parameter | Value | Default | | ||
|-----------| ----- | ------- | | ||
| linkedplaces | 0 or 1 | 1 | | ||
|
||
Include a details of places that are linked with this one. Places get linked | ||
Include details of places that are linked with this one. Places get linked | ||
together when they are different forms of the same physical object. Nominatim | ||
links two kinds of objects together: place nodes get linked with the | ||
corresponding administrative boundaries. Waterway relations get linked together with their | ||
members. | ||
(Default: 1) | ||
|
||
* `hierarchy=[0|1]` | ||
| Parameter | Value | Default | | ||
|-----------| ----- | ------- | | ||
| hierarchy | 0 or 1 | 0 | | ||
|
||
Include details of places lower in the address hierarchy. | ||
|
||
`[Python-only]` will only return properly parented places. These are address | ||
or POI-like places that reuse the address of their parent street or place. | ||
|
||
Include details of places lower in the address hierarchy. (Default: 0) | ||
| Parameter | Value | Default | | ||
|-----------| ----- | ------- | | ||
| group_hierarchy | 0 or 1 | 0 | | ||
|
||
* `group_hierarchy=[0|1]` | ||
When set to 1, the output of the address hierarchy will be | ||
grouped by type. | ||
|
||
For JSON output will group the places by type. (Default: 0) | ||
| Parameter | Value | Default | | ||
|-----------| ----- | ------- | | ||
| polygon_geojson | 0 or 1 | 0 | | ||
|
||
* `polygon_geojson=[0|1]` | ||
|
||
Include geometry of result. (Default: 0) | ||
Include geometry of result. | ||
|
||
### Language of results | ||
|
||
* `accept-language=<browser language string>` | ||
| Parameter | Value | Default | | ||
|-----------| ----- | ------- | | ||
| accept-language | browser language string | content of "Accept-Language" HTTP header | | ||
|
||
Preferred language order for showing result, overrides the value | ||
specified in the "Accept-Language" HTTP header. | ||
Either use a standard RFC2616 accept-language string or a simple | ||
comma-separated list of language codes. | ||
Preferred language order for showing search results. This may either be | ||
a simple comma-separated list of language codes or have the same format | ||
as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language). | ||
|
||
|
||
## Examples | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to serve