Skip to content

Commit

Permalink
Traefik setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Nov 30, 2023
1 parent d756d6f commit 1ddfaa7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 265 deletions.
28 changes: 10 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
# localstrfry

localstrfry is an example project aimed at demonstrating how to set up and customize a local instance of the strfry relay using Docker. It's a useful resource for those looking to experiment with different Nginx configurations in conjunction with strfry. This project is suitable for developers and enthusiasts wanting to explore relay customization in a local environment and experiment with Nginx setups.

## Features

- **Custom HTML Page**: Instructions on how to override the default HTML page of the strfry relay.
- **Nginx Configuration Flexibility**: Suitable for experimenting with various Nginx configurations behind the strfry relay.
- **Local Relay Setup for Learning**: Perfect for setting up the strfry relay in a local, non-production environment.
- **Simple Docker-Compose Setup**: Utilizes docker-compose for straightforward setup.
localstrfry is an example project aimed at demonstrating how to set up and customize a local instance of the [strfry relay](https://github.com/hoytech/strfry) for the Nostr network using Docker. This project serves as a practical resource for developers and enthusiasts interested in exploring relay customization in a local environment, particularly for those involved with [Nostr](https://nostr.com/), a decentralized social network. The setup showcases the integration of Traefik and Nginx for effective service routing and redirection.

## Prerequisites

- Docker and Docker Compose installed on your machine.
- Familiarity with Docker concepts and Nginx configuration.
- Basic familiarity with Docker concepts, and Traefik and Nginx configuration.

## Installation and Usage

1. **Clone the Repository**:
```bash
git clone https://github.com/planetary-social/localstrfry.git
```

2. **Navigate to the Project Directory**:
```bash
cd localstrfry
```

3. **Start the Relay using Docker Compose**:
- This command downloads necessary images and starts the services defined in the \`docker-compose.yml\` file.
```bash
docker-compose up
```
4. **Accessing the Custom HTML Page**:
- Visit `http://localhost:8080` to see your custom HTML page after the relay starts.

## Customization

- To change the default HTML page, edit `index.html` in the `html/relay_home` directory.
- Modify the Nginx configurations in the `nginx` directory to try out different setups.
4. **Accessing the Custom HTML Page**:
- Visit \`http://localhost\` to access a custom HTML page, which differs from the default strfry relay page. This page is served by the \`redirect-service\`, demonstrating the usage of Nginx for content redirection.

## Additional Resources
## Adding SSL/TLS with Traefik

- For setting up the strfry relay on a VPS with proper SSL, review [this guide](https://relayable.org/strfry-relay-howto.html). It's informative for running strfry in a more production-oriented environment, but doesn't include setting up `index.html`.
To secure your relay with SSL/TLS, follow the [Traefik HTTPS setup instructions](https://doc.traefik.io/traefik/https/overview/). This involves configuring Traefik with a certificate resolver for automatic SSL certificate generation and renewal, making your relay suitable for a more secure, production-oriented environment.

## Contributing

Contributions to localstrfry are welcome. Please follow the standard GitHub pull request process for any improvements or ideas.
Contributions to localstrfry are welcome. If you have ideas for improvements or additional features, please follow the standard GitHub pull request process.

## License

Expand Down
47 changes: 31 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
version: '3'
---
version: "3.3"

services:
openresty:
image: openresty/openresty:1.21.4.3-1-jammy

traefik:
image: "traefik:v2.10"
container_name: "traefik"
command:
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- '80:80'
- '443:443'
- "80:80"
volumes:
- ./openresty/nginx.default.conf:/etc/nginx/conf.d/default.conf
- ./html:/usr/local/openresty/nginx/html
- ./openresty/letsencrypt:/etc/letsencrypt
depends_on:
- strfry
- "/var/run/docker.sock:/var/run/docker.sock:ro"

strfry:
image: relayable/strfry:latest
container_name: "strfry"
restart: always
volumes:
- ./strfry/config/strfry.conf:/etc/strfry.conf
- ./strfry/db:/app/strfry-db
- ./strfry/plugins:/app/plugins
certbot:
image: certbot/certbot
container_name: certbot
labels:
- "traefik.enable=true"
- "traefik.http.routers.strfry.rule=Headers(`Accept`, `application/nostr+json`) || HeadersRegexp(`Connection`, `(?i)Upgrade`)" #" && HeadersRegexp(`Upgrade`, `websocket`)"
- "traefik.http.routers.strfry.entrypoints=web"
- "traefik.http.services.strfry.loadbalancer.server.port=7777"

redirect-service:
image: nginx:alpine
container_name: "redirect-service"
restart: always
volumes:
- ./openresty/letsencrypt:/etc/letsencrypt
- ./html:/usr/local/openresty/nginx/html
command: certonly --webroot -w /usr/local/openresty/nginx/html --force-renewal --email [email protected] -d relay.nos.social --agree-tos
- ./redirect-service/nginx-redirect.conf:/etc/nginx/conf.d/default.conf
labels:
- "traefik.enable=true"
- "traefik.http.routers.redirect-service.rule=Host(`localhost`)"
- "traefik.http.routers.redirect-service.entrypoints=web"
- "traefik.http.services.redirect-service.loadbalancer.server.port=80"

160 changes: 0 additions & 160 deletions html/relay_home/index.html

This file was deleted.

Binary file removed html/relay_home/screenshot.png
Binary file not shown.
71 changes: 0 additions & 71 deletions openresty/nginx.default.conf

This file was deleted.

12 changes: 12 additions & 0 deletions redirect-service/nginx-redirect.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resolver 8.8.8.8;

server {
listen 80;
server_name host.docker.internal;

location / {
proxy_ssl_server_name on;
proxy_set_header Host nos-relay.webflow.io;
proxy_pass https://nos-relay.webflow.io$request_uri;
}
}

0 comments on commit 1ddfaa7

Please sign in to comment.