YOURLS是一套很广泛使用的免费的网址缩短器,而且其自带分析报表以及许多好用的外挂,非常值得使用! ? 我也装了一套建立自己的短网址服务,在VestaCP虚拟主机管理系统的服务下可以很快地将环境部属起来~ ?
初始化环境设定
操作前请自行将go.520.be取代成要设定的网址,并且准备好帐号名称以及八位数以上的密码
—
# 网址: https://go.520.be
# 管理员帐号: 自订帐号名称 (仅限使用英文或数字)
# 管理员密码: 八位数以上的密码 (仅限使用英文或数字)
# 本机路径: /home/admin/web/go.520.be/public_html
# MySQL资料库名称: admin_go
# MySQL帐号: admin_go
# MySQL密码: 八位数以上的密码 (仅限使用英文或数字)
—
STEP-1. 在SSH画面中输入下列指令增加网站
1 2 3 |
v-add-web-domain admin go.520.be v-add-database admin go go 八位数以上的密码 mysql v-add-letsencrypt-domain admin go.520.be |
STEP-2A. 安装YOURLS主程式
1 2 3 4 |
cd /home/admin/web/go.520.be/public_html git clone https://github.com/YOURLS/YOURLS.git mv YOURLS/* /home/admin/web/go.520.be/public_html/ rm -fr mv YOURLS |
STEP-2B. 安装繁体中文语系档
1 2 3 4 |
wget -O /home/admin/web/go.520.be/public_html/user/languages/zh_TW.mo https://github.com/0995101008/awesome-yourls/raw/master/zh_TW.mo wget -O /home/admin/web/go.520.be/public_html/user/languages/zh_TW.po https://github.com/0995101008/awesome-yourls/raw/master/zh_TW.po sed -i "s/'YOURLS_LANG', '.*'/'YOURLS_LANG', 'zh_TW'/g" /home/admin/web/go.520.be/public_html/user/config.php cat /home/admin/web/go.520.be/public_html/user/config.php | grep YOURLS_LANG |
STEP-3. 新增网站的.htaccess
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
cat <<"EOF" > /home/admin/web/go.520.be/public_html/.htaccess # BEGIN YOURLS <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ /yourls-loader.php [L] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] </IfModule> # END YOURLS EOF clear cat /home/admin/web/go.520.be/public_html/.htaccess |
编辑设定档
STEP-4A. 编辑设定档 ~ 设定MySQL帐密
# MySQL密码: 八位数以上的密码
rm -f /home/admin/web/go.520.be/public_html/user/config.php
cp /home/admin/web/go.520.be/public_html/user/config-sample.php /home/admin/web/go.520.be/public_html/user/config.php
sed -i "s/'YOURLS_DB_NAME', '.*'/'YOURLS_DB_NAME', 'admin_go'/g" /home/admin/web/go.520.be/public_html/user/config.php
sed -i "s/'YOURLS_DB_USER', '.*'/'YOURLS_DB_USER', 'admin_go'/g" /home/admin/web/go.520.be/public_html/user/config.php
sed -i "s/'YOURLS_DB_PASS', '.*'/'YOURLS_DB_PASS', '八位数以上的密码'/g" /home/admin/web/go.520.be/public_html/user/config.php
cat /home/admin/web/go.520.be/public_html/user/config.php | grep YOURLS_DB
# vi +/YOURLS_DB /home/admin/web/go.520.be/public_html/user/config.php
STEP-4B. 编辑设定档 ~ 随机产生COOKIE KEY
1 2 3 |
sed -i "s/'YOURLS_COOKIEKEY', '.*'/'YOURLS_COOKIEKEY', '`cat /dev/urandom | head -1 | md5sum | head -c 32`'/g" /home/admin/web/go.520.be/public_html/user/config.php cat /home/admin/web/go.520.be/public_html/user/config.php | grep YOURLS_COOKIEKEY # vi +/YOURLS_COOKIEKEY /home/admin/web/go.520.be/public_html/user/config.php |
STEP-4C. 编辑设定档 ~ 设定管理员帐密,请输入自订的管理员帐密
sed -i "s#'username' => 'password'#'自订帐号名称' => '八位数以上的密码'#g" /home/admin/web/go.520.be/public_html/user/config.php
# vi +/yourls_user_passwords /home/admin/web/go.520.be/public_html/user/config.php
STEP-4D. 编辑设定档 ~ 设定网址
1 2 3 |
sed -i "s#'YOURLS_SITE', '.*'#'YOURLS_SITE', 'https://go.520.be'#g" /home/admin/web/go.520.be/public_html/user/config.php cat /home/admin/web/go.520.be/public_html/user/config.php | grep YOURLS_SITE # vi +/YOURLS_SITE /home/admin/web/go.520.be/public_html/user/config.php |
STEP-4E. 编辑设定档 ~ 设定时区
1 2 3 |
sed -i "s#YOURLS_HOURS_OFFSET', 0#YOURLS_HOURS_OFFSET', +8#g" /home/admin/web/go.520.be/public_html/user/config.php cat /home/admin/web/go.520.be/public_html/user/config.php | grep YOURLS_HOURS_OFFSET # vi +/YOURLS_HOURS_OFFSET /home/admin/web/go.520.be/public_html/user/config.php |
安装外挂模组
STEP-5A. 安装外挂模组 ~ Random Keywords
1 2 3 |
cd /home/admin/web/go.520.be/public_html/user/plugins rm -fr /home/admin/web/go.520.be/public_html/user/plugins/random-keywords git clone https://github.com/yourls/random-keywords.git |
STEP-5B. 安装外挂模组 ~ Antispam
1 2 3 |
cd /home/admin/web/go.520.be/public_html/user/plugins rm -fr /home/admin/web/go.520.be/public_html/user/plugins/antispam git clone https://github.com/yourls/antispam.git |
STEP-5C. 安装外挂模组 ~ Cache Stats pages
1 2 3 |
cd /home/admin/web/go.520.be/public_html/user/plugins rm -fr /home/admin/web/go.520.be/public_html/user/plugins/cache-stats-pages git clone https://github.com/yourls/cache-stats-pages.git |
STEP-5D. 安装外挂模组 ~ Don’t Log Bots
1 2 3 |
cd /home/admin/web/go.520.be/public_html/user/plugins rm -fr /home/admin/web/go.520.be/public_html/user/plugins/dont-log-bots git clone https://github.com/yourls/dont-log-bots.git |
STEP-5E. 安装外挂模组 ~ Mass Remove Links
1 2 3 |
cd /home/admin/web/go.520.be/public_html/user/plugins rm -fr /home/admin/web/go.520.be/public_html/user/plugins/mass-remove-links git clone https://github.com/yourls/mass-remove-links.git |
STEP-5F. 安装外挂模组 ~ Google Safe Browsing
1 2 3 |
cd /home/admin/web/go.520.be/public_html/user/plugins rm -fr /home/admin/web/go.520.be/public_html/user/plugins/google-safe-browsing git clone https://github.com/YOURLS/google-safe-browsing.git |
安装布景主题
STEP-6A. 安装Sleeky布景主题
1 2 3 4 5 6 7 |
cd /home/admin/web/go.520.be/public_html/user/plugins rm -fr /home/admin/web/go.520.be/public_html/user/plugins/Sleeky git clone https://github.com/Flynntes/Sleeky.git mv /home/admin/web/go.520.be/public_html/user/plugins/Sleeky/sleeky-frontend/* /home/admin/web/go.520.be/public_html mv /home/admin/web/go.520.be/public_html/user/plugins/Sleeky/sleeky-backend/* /home/admin/web/go.520.be/public_html/user/plugins/Sleeky rm -fr /home/admin/web/go.520.be/public_html/user/plugins/Sleeky/sleeky-backend rm -fr /home/admin/web/go.520.be/public_html/user/plugins/Sleeky/sleeky-frontend |
STEP-6B. 设定网址
1 2 |
sed -i "s#'siteURL', '*.*'#'siteURL', 'https://go.520.be'#g" /home/admin/web/go.520.be/public_html/frontend/config.php cat /home/admin/web/go.520.be/public_html/frontend/config.php | grep siteURL |
STEP-6C. 设定网页标题
1 2 |
sed -i "s#'title', '.*'#'title', '缩网址 | 把又臭又长的网址变得整洁美观'#g" /home/admin/web/go.520.be/public_html/frontend/config.php cat /home/admin/web/go.520.be/public_html/frontend/config.php | grep "define('title'" |
STEP-6D. 设定网页左下方显示的网站名称
1 2 |
sed -i "s#'shortTitle', '.*'#'shortTitle', '缩网址 | 逆向行驶'#g" /home/admin/web/go.520.be/public_html/frontend/config.php cat /home/admin/web/go.520.be/public_html/frontend/config.php | grep shortTitle |
STEP-6E. 设定网页描述
1 2 |
sed -i "s#'description', '.*'#'description', '多功能缩址服务,完全免费、免登入、自带数据统计功能'#g" /home/admin/web/go.520.be/public_html/frontend/config.php cat /home/admin/web/go.520.be/public_html/frontend/config.php | grep description |
STEP-6F. 设定每日更换背景图片
1 2 |
sed -i "s#// define('backgroundImage'#define('backgroundImage'#g" /home/admin/web/go.520.be/public_html/frontend/config.php cat /home/admin/web/go.520.be/public_html/frontend/config.php | grep backgroundImage |
STEP-6G. 重设所有档案权限
1 2 3 4 5 6 |
rm -fr /home/admin/web/go.520.be/public_html/user/plugins/sample-* rm -fr /home/admin/web/go.520.be/public_html/user/plugins/random-shorturls rm -fr /home/admin/web/go.520.be/public_html/user/plugins/hyphens-in-urls chown -R admin:admin /home/admin/web/go.520.be/public_html find /home/admin/web/go.520.be/public_html -type d -exec chmod 755 {} \; find /home/admin/web/go.520.be/public_html -type f -exec chmod 644 {} \; |
网站设定
虽然步骤看似有点长,但其实只要先设定环境,将上面所有的程式码存到文字档案,再设定好了帐密的部分,是可以一次贴上到SSH的,机器速度不差的,1分钟就能安装好整个YOURLS ?
操作完成后登入网站时,然后按图索骥先到Manage Plugins启动所有的外挂以及布景主题,然后再到Google API申请一个Safe Browsing API,然后将金钥填上即可 ?
ref.