feat: improve reverse proxy setup for production
Updated README with detailed instructions for setting environment variables via a .env file. Added sample Caddyfile for reverse proxy configuration and systemd service files for managing the tracker and application. These enhancements streamline deployment, especially in production environments, by providing clear guidance and automation options. Resolves #1
This commit is contained in:
parent
2394a9f6ee
commit
13a771214a
4 changed files with 75 additions and 16 deletions
32
README.md
32
README.md
|
@ -39,15 +39,6 @@ npm install
|
|||
|
||||
3. Optional, but recommended for production: Put the application (:8105) and the tracker (:8106) behind a reverse proxy (e.g. Caddy or nginx) and configure SSL.
|
||||
|
||||
## Configuration
|
||||
|
||||
You can configure the application using environment variables:
|
||||
|
||||
- `TRACKER_URL`: The WebTorrent tracker URL (default: `ws://localhost:8106`)
|
||||
- `STUN_SERVER_URL`: The STUN server URL (optional - not used if unset)
|
||||
- `TURN_SERVER_URL`: The TURN server URL (optional - not used if unset)
|
||||
- `TURN_SECRET`: The static-auth-secret for the TURN server (required if `TURN_SERVER_URL` is set)
|
||||
|
||||
## Running the Application
|
||||
|
||||
1. Start the tracker:
|
||||
|
@ -56,17 +47,27 @@ You can configure the application using environment variables:
|
|||
npm run tracker
|
||||
```
|
||||
|
||||
2. Set the environment variables and start the server:
|
||||
2. Create a `.env` file in the root directory of the project and set the environment variables:
|
||||
|
||||
```bash
|
||||
export TRACKER_URL="wss://tracker.your-domain.com" # URL of the WebTorrent tracker - default: ws://localhost:8106, use wss:// for secure connections
|
||||
export STUN_SERVER_URL="stun:stun.nextcloud.com:443" # Optional - there are public STUN servers available - not used if unset
|
||||
export TURN_SERVER_URL="turn:your-turn-server-url" # Optional - you would need to set up your own TURN server - don't set this if you don't have one
|
||||
export TURN_SECRET="your-static-auth-secret" # Required if you have a TURN server - don't set this if you don't have one
|
||||
TRACKER_URL="wss://tracker.your-domain.com" # URL of the WebTorrent tracker - default: ws://localhost:8106, use wss:// for secure connections
|
||||
STUN_SERVER_URL="stun:stun.nextcloud.com:443" # Optional - there are public STUN servers available - not used if unset
|
||||
TURN_SERVER_URL="turn:your-turn-server-url" # Optional - you would need to set up your own TURN server - don't set this if you don't have one
|
||||
TURN_SECRET="your-static-auth-secret" # Required if you have a TURN server - don't set this if you don't have one
|
||||
```
|
||||
|
||||
If you are using a reverse proxy, you should set the `TRACKER_URL` to the URL of the tracker behind the reverse proxy, e.g. `wss://tracker.your-domain.com`.
|
||||
|
||||
The STUN and TURN server URLs should be set to the public URLs of your STUN and TURN servers, if you have them.
|
||||
|
||||
3. Start the application:
|
||||
|
||||
```bash
|
||||
. .env
|
||||
npm start
|
||||
```
|
||||
|
||||
3. Open your browser and navigate to `http://localhost:8105` (or the URL you have configured in your reverse proxy)
|
||||
4. Open your browser and navigate to `http://localhost:8105` (or the URL you have configured in your reverse proxy)
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -85,4 +86,3 @@ npm start
|
|||
## License
|
||||
|
||||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
||||
|
||||
|
|
9
contrib/caddy/Caddyfile
Normal file
9
contrib/caddy/Caddyfile
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Simple example of how to use Caddy for Transfer.coffee
|
||||
|
||||
transfer.example www.transfer.example {
|
||||
reverse_proxy localhost:8105
|
||||
}
|
||||
|
||||
tracker.transfer.example {
|
||||
reverse_proxy localhost:8106
|
||||
}
|
23
contrib/systemd/transfercoffee-tracker.service
Normal file
23
contrib/systemd/transfercoffee-tracker.service
Normal file
|
@ -0,0 +1,23 @@
|
|||
[Unit]
|
||||
Description=Transfer.coffee Tracker
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
RestartSec=2s
|
||||
Type=simple
|
||||
|
||||
User=transfercoffee
|
||||
Group=transfercoffee
|
||||
|
||||
# Replace /opt/transfer.coffee with where you cloned the repo to
|
||||
WorkingDirectory=/opt/transfer.coffee
|
||||
ExecStart=/usr/bin/npm run tracker
|
||||
|
||||
Restart=always
|
||||
RestartSec=86400s
|
||||
|
||||
LimitNOFILE=infinity
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
27
contrib/systemd/transfercoffee.service
Normal file
27
contrib/systemd/transfercoffee.service
Normal file
|
@ -0,0 +1,27 @@
|
|||
[Unit]
|
||||
Description=Transfer.coffee
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
RestartSec=2s
|
||||
Type=simple
|
||||
|
||||
# Replace this with the user you want to run as
|
||||
User=transfercoffee
|
||||
Group=transfercoffee
|
||||
|
||||
# Replace /opt/transfer.coffee with where you cloned the repo to
|
||||
WorkingDirectory=/opt/transfer.coffee
|
||||
ExecStart=/usr/bin/npm run start
|
||||
|
||||
# Create a .env file in the root of the project with the environment variables (see README.md)
|
||||
EnvironmentFile = /opt/transfer.coffee/.env
|
||||
|
||||
Restart=always
|
||||
RestartSec=86400s
|
||||
|
||||
LimitNOFILE=infinity
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in a new issue