Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# For more information, refer to our documentation: https://docs.swetrix.com/selfhosting/configuring

# Swetrix Frontend configuration
API_URL=http://localhost:8080
# Public URL where your Swetrix instance is reachable (no trailing slash).
BASE_URL=http://localhost

# Swetrix API configuration

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ git clone https://github.com/swetrix/selfhosting
cd selfhosting
```
2. [Install Docker](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04?ref=swetrix.com) if you haven't already.
3. Configure the environment variables for your Swetrix instance. It can be easily done by running `./configure.sh` script, which will ask you to provide the necessary values and generate a `.env` file with them. A table explaining what each value means can be found [here](https://docs.swetrix.com/selfhosting/configuring).
3. Configure the environment variables for your Swetrix instance. It can be easily done by running `./configure.sh` script, which will ask you to provide the necessary values (including `BASE_URL`) and generate a `.env` file with them. See the [configuration variable reference](https://docs.swetrix.com/selfhosting/configuring).
4. Run `docker compose up -d` to start the Swetrix services.
5. After that, you will be able to access Swetrix web portal on the port you specified in `swetrix` category in `compose.yaml` (by default, it's set to `80`).
5. After that, you will be able to access Swetrix web portal at the URL you set in `BASE_URL` (by default, `http://localhost`).

And that's it! :) If you have any questions, feel free to join our [Discord community](https://discord.gg/ZVK8Tw2E8j). You can also star our [main repository](https://github.com/Swetrix/swetrix) as a token of appreciation.
22 changes: 17 additions & 5 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ services:
restart: always
depends_on:
- swetrix-api
ports:
- "80:3000"
environment:
- API_URL=${API_URL}
- BASE_URL=${BASE_URL}
healthcheck:
test:
[
Expand All @@ -23,8 +21,6 @@ services:
image: swetrix/swetrix-api:v4.1.0
restart: always
container_name: swetrix-api
ports:
- "8080:5005"
environment:
# Configurable with .env file
- SECRET_KEY_BASE=${SECRET_KEY_BASE}
Expand Down Expand Up @@ -114,6 +110,22 @@ services:
nofile:
soft: 262144
hard: 262144

nginx-proxy:
image: nginx:1.29.4-alpine
restart: always
depends_on:
swetrix:
condition: service_healthy
swetrix-api:
condition: service_healthy
links:
- "swetrix-api"
- "swetrix"
ports:
- "80:80"
volumes:
- ./nginx/config:/etc/nginx/conf.d/default.conf
volumes:
swetrix-events-data:
driver: local
13 changes: 7 additions & 6 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,16 @@ echo -e "${GREEN}Creating new .env file...${NC}"

echo -e "# Swetrix Frontend configuration" > .env

# API_URL
# BASE_URL
while true; do
echo
read -e -p "Enter API_URL of your Swetrix API instance (required, e.g., https://api.swetrix.example.com): " api_url
if [ -n "$api_url" ]; then
echo "API_URL=$api_url" >> .env
echo
read -e -p "Enter public URL of your Swetrix instance (required, e.g., https://swetrix.example.com): " base_url
if [ -n "$base_url" ]; then
base_url="${base_url%/}"
echo "BASE_URL=$base_url" >> .env
break
else
echo -e "${RED}API_URL is required. Please enter a value.${NC}"
echo -e "${RED}BASE_URL is required. Please enter a value.${NC}"
fi
Comment thread
Blaumaus marked this conversation as resolved.
done

Expand Down
75 changes: 58 additions & 17 deletions nginx/config
Original file line number Diff line number Diff line change
@@ -1,27 +1,68 @@
map $http_upgrade $connection_upgrade {
default upgrade;
"" close;
}

server {
listen 81;
listen [::]:81;
# server_name swetrix.yourdomain.com;
listen 80;
listen [::]:80;
server_name _;

location / {
proxy_pass http://localhost:80;
# security headers
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "interest-cohort=()" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

# Keep /backend/ prefix; this is used to route requests to the Swetrix API.
location /backend/ {
proxy_pass http://swetrix-api:5005/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

server {
listen 8081;
listen [::]:8081;
# server_name api.swetrix.yourdomain.com;
server_name _;
# Proxy headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;

# Proxy buffering (prevents truncated responses for large files)
proxy_buffering on;
proxy_buffer_size 256k;
proxy_buffers 32 512k;
proxy_busy_buffers_size 4m;
proxy_max_temp_file_size 1024m;
}

location / {
proxy_pass http://localhost:8080;
proxy_pass http://swetrix:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# Proxy headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;

# Proxy buffering (prevents truncated responses for large files)
proxy_buffering on;
proxy_buffer_size 256k;
proxy_buffers 32 512k;
proxy_busy_buffers_size 4m;
proxy_max_temp_file_size 1024m;
}

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
}