Scripts2026年4月20日·1 分钟阅读

Shlink — Self-Hosted URL Shortener with Analytics

Shlink is a self-hosted URL shortener that lets you create short links with full analytics, QR codes, and API access. Built with PHP, it supports custom domains and provides detailed visit tracking.

SC
Script Depot · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

docker run -d --name shlink 
  -p 8080:8080 
  -e DEFAULT_DOMAIN=s.example.com 
  -e IS_HTTPS_ENABLED=true 
  shlinkio/shlink:stable
# API available at http://localhost:8080
# Generate API key: docker exec shlink shlink api-key:generate

Introduction

Shlink is a self-hosted URL shortening service that gives you full ownership of your short links and their analytics. Built with PHP on the Mezzio framework, it provides a REST API for creating and managing short URLs, detailed visit statistics with geolocation, and QR code generation. A separate web client offers a management dashboard for non-technical users.

What Shlink Does

  • Creates short URLs with custom slugs, tags, and expiration dates
  • Tracks visits with geolocation, referrer, browser, and device data
  • Generates QR codes for any short URL automatically
  • Supports multiple custom domains from a single instance
  • Provides a REST API for programmatic URL management

Self-Hosting & Configuration

  • Deploy with Docker using a single container and environment variables
  • Connect to PostgreSQL, MySQL, or MariaDB for production storage
  • Configure GeoLite2 database for visitor geolocation tracking
  • Set up the Shlink Web Client for a browser-based management UI
  • Use environment variables to control URL validation and redirect behavior

Key Features

  • Multi-domain support with per-domain short URL namespaces
  • Real-time visit webhooks for integration with external analytics
  • URL validation to prevent shortening broken or malicious links
  • Bot detection and filtering in visit statistics
  • Import short URLs from Bitly, YOURLS, or CSV files

Architecture Overview

Shlink is a PHP application built on the Mezzio microframework with Doctrine ORM for database access. It runs as a self-contained Swoole or RoadRunner server inside Docker, requiring no external web server. Visit tracking data is stored in the relational database with optional GeoLite2 lookups for IP geolocation. The REST API follows a consistent JSON schema with API key authentication.

Comparison with Similar Tools

  • YOURLS — PHP-based but older architecture; fewer analytics features
  • Kutt — Node.js alternative; smaller community and fewer integrations
  • Bitly — SaaS-only; not self-hostable
  • Polr — abandoned project; no longer actively maintained

FAQ

Q: Does Shlink require a web server like Nginx or Apache? A: No. The Docker image runs a built-in Swoole or RoadRunner server. You only need a reverse proxy for TLS termination.

Q: Can I use multiple custom domains? A: Yes. Configure additional domains in the admin UI or via the API. Each domain can have its own set of short URLs.

Q: How does visit tracking work? A: Each redirect logs the visitor's IP, user agent, referrer, and timestamp. Shlink resolves IPs to locations using the GeoLite2 database.

Q: Can I migrate from Bitly to Shlink? A: Yes. Shlink includes a built-in importer that reads Bitly export files and recreates your short URLs with their original slugs.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产