Added API testing and TLS Encryption for Nginx.

This commit is contained in:
2025-04-07 12:57:38 +03:00
parent 7c0f7d9bea
commit a1c2f382d0

View File

@@ -31,7 +31,7 @@ This repository includes:
- [Using the `test_setup` command:](#using-the-test_setup-command) - [Using the `test_setup` command:](#using-the-test_setup-command)
- [Run it and make it available to use](#run-it-and-make-it-available-to-use) - [Run it and make it available to use](#run-it-and-make-it-available-to-use)
- [Create your first admin user](#create-your-first-admin-user) - [Create your first admin user](#create-your-first-admin-user)
- [Expose the API](#expose-the-api) - [Using Nginx](#using-nginx)
## Getting Started ## Getting Started
@@ -249,12 +249,17 @@ Enter role (admin/user): admin
You don't need passwords for this, just the username and role. You don't need passwords for this, just the username and role.
### Expose the API #### Using Nginx
This app currently runs on your local network only, we need to expose it so the data consumer on the Data Analysis product can access it and consume the data it provides. Nginx is a great reverse-proxy that supports connection polling and real-time connections like Webhook and Server Site Events.
1. Install & Update Nginx:
`sudo apt install nginx --upgrade`
2. Create the config file: 2. Create the config file:
Create a config file in a path like this:
`/etc/nginx/sites-available/your_domain_com.conf` `/etc/nginx/sites-available/your_domain_com.conf`
```bash ```bash
@@ -302,6 +307,39 @@ sudo systemctl restart nginx
``` ```
2. Test the API (HTTP)
On your browser, head to: `http://your_domain.com/ping`
It should show **"Ok"**
3. Implement TLS Encryption
You can use and certificate provided, we'll show you how to use Certbot Setup (Lets Encrypt TLS) to obtain a free certificate.
Run this after Nginx is live on port 80 (ensure DNS points to your server!):
```bash
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d your_domain.com # Replace with your domain
```
Certbot will auto-configure Nginx to use HTTPS and redirect HTTP → HTTPS.
Certificates auto-renew (add a cron job if not existing):
```bash
sudo certbot renew --dry-run
```
4. Test the API (HTTP/TLS)
On your browser, head to: `https://your_domain.com/ping`
> Notice the **s** in http**s**
It should show **"Ok"**
--- ---