爱极客专注分享-好玩的docker应用-源码分享
【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

YOURLS,感受到短链接生成的乐趣。

本博客用什么vps?创作不易,欢迎请作者喝杯咖啡☕☕☕

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

官方文档:https://yourls.org

【服务器能干什么】搭建一个短网址平台,可以查看数据详情![【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

简单介绍

什么是YOURLS?

YOURLS stands for Your Own URL Shortener. It is a small set of PHP scripts that will allow you to run your own URL shortening service (a la TinyURL or Bitly).

Running your own URL shortener is fun, geeky and useful: you own your data and don’t depend on third-party services. It’s also a great way to add branding to your short URLs, instead of using the same public URL shortener everyone uses.

大概意思就是说YOURLS,这个基于PHP开发的短链接服务,适用于私有,且不依赖第三方公共短链接生成。你只需要有一定的耐心和一个短域名,就可以感受到短链接生成的乐趣。

特点

  • 免费而且开源
  • 使用具有两面性:私有的(仅自己使用)或者生成公共的(每个人都可以创建短链接,适用于Intranet)
  • 顺序排列(从1到n)或自定义URL关键字
  • 十分方便的类书签模式记录,可轻松缩短和共享链接
  • 出色的统计信息:历史点击报告,引荐来源跟踪,访问者地理位置
  • 整洁的Ajaxed界面
  • 出色的插件架构,可轻松实现新功能
  • 支持开发人员API
  • 全面的jsonp支持
  • 安装十分友好
  • 示例文件可创建您自己的公共界面等

下面是一步一步的安装记录。

安装环境

新建站点

首先,打开宝塔面板,我们来添加一个已经解析好的网站。

安装数据库,php。

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

然后给域名申请一个SSL证书:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

开启强制https:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

设置伪静态:

  location / {
    try_files $uri $uri/ /yourls-loader.php$is_args$args;
  }
【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

下载源码

到github上下载最新版本:

https://github.com/YOURLS/YOURLS/releases

目前最新的是1.9.2

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

当然如果我们的服务器不在大陆的话,还可以用服务器来下载,速度会快很多。

方法如下:

打开网站根目录:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

【服务器能干什么】搭建一个短网址平台,可以查看数据详情![![【服务器能干什么】搭

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!下载好了之后,直接点解压:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

打开YOURLS-1.7.9文件夹,全选里面的内容,粘贴到网站根目录:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!
【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

接下来打开目录/user/,把里面的config-sample.php改成config.php

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

然后我们来编辑里面的内容:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

打开之后是这样的:

<?php
/* This is a sample config file.
 * Edit this file with your own settings and save it as "config.php"
 *
 * IMPORTANT: edit and save this file as plain ASCII text, using a text editor, for instance TextEdit on Mac OS or
 * Notepad on Windows. Make sure there is no character before the opening <?php at the beginning of this file.
 */

/*
 ** MySQL settings - You can get this info from your web host
 */

/** MySQL database username */
define( 'YOURLS_DB_USER', 'your db user name' );

/** MySQL database password */
define( 'YOURLS_DB_PASS', 'your db password' );

/** The name of the database for YOURLS */
define( 'YOURLS_DB_NAME', 'yourls' );

/** MySQL hostname.
 ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */
define( 'YOURLS_DB_HOST', 'localhost' );

/** MySQL tables prefix */
define( 'YOURLS_DB_PREFIX', 'yourls_' );

/*
 ** Site options
 */

/** YOURLS installation URL -- all lowercase, no trailing slash at the end.
 ** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) */
define( 'YOURLS_SITE', 'http://your-own-domain-here.com' );

/** Server timezone GMT offset */
define( 'YOURLS_HOURS_OFFSET', 0 ); 

/** YOURLS language
 ** Change this setting to use a translation file for your language, instead of the default English.
 ** That translation file (a .mo file) must be installed in the user/language directory.
 ** See http://yourls.org/translations for more information */
define( 'YOURLS_LANG', '' ); 

/** Allow multiple short URLs for a same long URL
 ** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)
 ** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */
define( 'YOURLS_UNIQUE_URLS', true );

/** Private means the Admin area will be protected with login/pass as defined below.
 ** Set to false for public usage (eg on a restricted intranet or for test setups)
 ** Read http://yourls.org/privatepublic for more details if you're unsure */
define( 'YOURLS_PRIVATE', true );

/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookie **/
define( 'YOURLS_COOKIEKEY', 'modify this text with something random' );

/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes
 ** YOURLS will auto encrypt plain text passwords in this file
 ** Read http://yourls.org/userpassword for more information */
$yourls_user_passwords = array(
    'username' => 'password',
    // 'username2' => 'password2',
    // You can have one or more 'login'=>'password' lines
    );

/** Debug mode to output some internal information
 ** Default is false for live site. Enable when coding or before submitting a new issue */
define( 'YOURLS_DEBUG', false );

/*
 ** URL Shortening settings
 */

/** URL shortening method: 36 or 62 */
define( 'YOURLS_URL_CONVERT', 36 );
/*
 * 36: generates all lowercase keywords (ie: 13jkm)
 * 62: generates mixed case keywords (ie: 13jKm or 13JKm)
 * Stick to one setting. It's best not to change after you've started creating links.
 */

/** 
* Reserved keywords (so that generated URLs won't match them)
* Define here negative, unwanted or potentially misleading keywords.
*/
$yourls_reserved_URL = array(
    'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick',
);

/*
 ** Personal settings would go after here.
 */

下面一条一条来说明:

define( 'YOURLS_DB_USER', 'your db user name' );  # 数据库用户名
define( 'YOURLS_DB_PASS', 'your db password' );   # 数据库密码
define( 'YOURLS_DB_NAME', 'yourls' );   # 数据库名称
define( 'YOURLS_DB_HOST', 'localhost' );   # 不用改

define( 'YOURLS_DB_PREFIX', 'yourls_' ); # 不用改

define( 'YOURLS_SITE', 'http://your-own-domain-here.com' ); # 你自己的域名 越短越好,比如我的loll.cc(再短的申请不到了。。。)短地址基于这个生成。
define( 'YOURLS_HOURS_OFFSET', 0 );   # 时区偏移 改成 8 
define( 'YOURLS_LANG', '' );  # 语言设置,默认是英文,后面我们改成中文版本,填'zh_CN'
define( 'YOURLS_UNIQUE_URLS', true );   # 不用改,短地址是否唯一 
define( 'YOURLS_PRIVATE', true );        # 不用改,是否私有,如果私有的,则进行api调用生成短地址时需要传递用户名和密码
define( 'YOURLS_COOKIEKEY', 'modify this text with something random' );    # 点击http://yourls.org/cookie 复制里面的密钥,这个不用记住的。
'username' => 'password',  # 用户名=>密码  可填多个  登录成功后这里的明文密码会被加密,这里默认是没有的,我们为了安全加上一个,比如用户名是'admin',密码是'123456'
define( 'YOURLS_DEBUG', false );  # 不用改,是否开启调试  
define( 'YOURLS_URL_CONVERT', 36 );     # 自己设置使用36进制 还是62进制  这个最好一开始设好不要修改,避免地址冲突,建议62进制
$yourls_reserved_URL = array(                                              
    'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick',
);  # 排除这些敏感词汇,这些地址是不会生成的

首先是数据库的相关信息,由于我们创建网站的时候已经创建好了数据库,所以,可以在这边找到数据库的情况:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

‘YOURLS_COOKIEKEY’的信息:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

填完之后,保存。

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

语言包地址:

https://github.com/ZvonimirSun/YOURLS-zh_CN

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

作者已经停止更新了貌似,不过还可以用,有能力的同学也可以帮忙翻译

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

语音包下载方法同上面讲过的,两种方法,自行选择。

我这里还是用服务器下载:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

同样,解压,然后把/user/languages/YOURLS-zh_CN-1.7.3的文件剪切出来:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!
【服务器能干什么】搭建一个短网址平台,可以查看数据详情!
【服务器能干什么】搭建一个短网址平台,可以查看数据详情!
【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

到这里应该基本上已经完成了,访问一下

浏览器 输入 https://域名/admin。

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

报错了!!

观察网站,可能是域名路径的问题,我之前在

define( 'YOURLS_SITE', 'http://your-own-domain-here.com' );

没有加https://,修改一下再看看:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

ok!

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

直接点击安装!

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

由于我们之前已经配置好的数据库等文件,所以这里直接显示完成了。

点击进入管理员页面,

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

输入账号密码就可以访问啦!

这边我提供一个测试账号给大家测试一下,账号admin,密码loll.cc,后续会关掉,仅仅供测试用噢。

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

添加一个网址:

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

压缩网址。

之后可以通过在短网址之后加上一个+号来查看数据情况。

【服务器能干什么】搭建一个短网址平台,可以查看数据详情!

可以愉快地玩起来了!

© 版权声明
THE END
喜欢就支持一下吧
点赞11赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容