... | ... | @@ -11,22 +11,20 @@ server { |
|
|
listen 80;
|
|
|
listen [::]:80;
|
|
|
|
|
|
server_name api.next.nomics.world;
|
|
|
server_name api.db.nomics.world;
|
|
|
|
|
|
access_log /var/log/nginx/api.next.nomics.world-access.log combined;
|
|
|
error_log /var/log/nginx/api.next.nomics.world-error.log warn;
|
|
|
access_log /var/log/nginx/api.db.nomics.world-access.log combined;
|
|
|
error_log /var/log/nginx/api.db.nomics.world-error.log warn;
|
|
|
|
|
|
location / { return 302 /v21$request_uri; }
|
|
|
location /v21 { try_files $uri @dbnomics_api_v21; }
|
|
|
|
|
|
location @dbnomics_api_v21 {
|
|
|
location /v21 {
|
|
|
include uwsgi_params;
|
|
|
uwsgi_pass localhost:8021;
|
|
|
}
|
|
|
|
|
|
listen 443 ssl; # managed by Certbot
|
|
|
ssl_certificate /etc/letsencrypt/live/api.next.nomics.world/fullchain.pem; # managed by Certbot
|
|
|
ssl_certificate_key /etc/letsencrypt/live/api.next.nomics.world/privkey.pem; # managed by Certbot
|
|
|
ssl_certificate /etc/letsencrypt/live/api.db.nomics.world/fullchain.pem; # managed by Certbot
|
|
|
ssl_certificate_key /etc/letsencrypt/live/api.db.nomics.world/privkey.pem; # managed by Certbot
|
|
|
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
|
|
|
|
|
|
# Explicitly allow HTTP for certain users who are behind proxies.
|
... | ... | @@ -37,25 +35,9 @@ server { |
|
|
}
|
|
|
```
|
|
|
|
|
|
### Systemd service file
|
|
|
|
|
|
`/etc/systemd/system/dbnomics-api-v21.service`:
|
|
|
|
|
|
```ini
|
|
|
[Service]
|
|
|
ExecStart=/usr/bin/uwsgi --ini /home/cepremap/production-config/dbnomics-api-uwsgi-v21.ini
|
|
|
Restart=always
|
|
|
User=cepremap
|
|
|
Group=cepremap
|
|
|
LimitNOFILE=65536
|
|
|
|
|
|
[Install]
|
|
|
WantedBy=multi-user.target
|
|
|
```
|
|
|
|
|
|
### uwsgi config
|
|
|
|
|
|
`/home/cepremap/production-config/dbnomics-api-uwsgi-v21.ini`:
|
|
|
As `cepremap`, create file `/home/cepremap/production-config/dbnomics-api-uwsgi-v21.ini`:
|
|
|
|
|
|
```ini
|
|
|
[uwsgi]
|
... | ... | @@ -76,5 +58,31 @@ enable-threads = true |
|
|
threads = 2
|
|
|
|
|
|
; Enable then use "uwsgitop :8001" to see processes.
|
|
|
; stats = :8001
|
|
|
stats = :8001
|
|
|
```
|
|
|
|
|
|
As `root`:
|
|
|
|
|
|
```bash
|
|
|
ln -s /home/cepremap/production-config/dbnomics-api-uwsgi-v21.ini /etc/uwsgi/apps-available/
|
|
|
cd /etc/uwsgi/apps-enabled
|
|
|
ln -s ../apps-available/dbnomics-api-uwsgi-v21.ini .
|
|
|
systemctl restart uwsgi.service
|
|
|
```
|
|
|
|
|
|
The logs of uwsgi applications are in `/var/log/uwsgi/app/`. To check that the service is well started, the last lines of `/var/log/uwsgi/app/dbnomics-api-uwsgi-v21.log` should display something like "spawned uWSGI worker 1 (and the only) (pid: 8936, cores: 1)" and not contain any error (grep for "Traceback" keyword).
|
|
|
|
|
|
To test: open https://api.dev.nomics.world/v21/
|
|
|
|
|
|
It should display:
|
|
|
|
|
|
```json
|
|
|
{
|
|
|
"_meta": {
|
|
|
"python_project_version": "0.19.0",
|
|
|
"python_project_name": "DBnomics-API"
|
|
|
},
|
|
|
"apidocs_href": "/apidocs",
|
|
|
"message": "This is the home page of DBnomics Web API. Its documentation is here: https://api.dev.nomics.world/apidocs"
|
|
|
}
|
|
|
``` |