YOURLS 短網址系統安裝教學(類似Bit.ly縮址應用)


隨著 Goolge 公司推出 Goo.gl 與其相關 API 後,網址縮短服務越來越被人們接收與使用。雖然不免暗藏駭客攻擊的危險,但是簡潔的短網址不論在有文字數量限制的 Twitter 與 Plurk 上貼文,或是公告特定網址時都能讓讀者感到清爽,在資訊傳達上也相當省力方便。

曼特斯研究所(mountos : institute)也自己安裝一套縮址服務「有我 All On Oon.me」給自家網站群使用。

如果你也想架設一組專用縮網址服務器,網路上「YOURLS」組織提供了方便安裝的伺服器套件。今天要來跟大家介紹套件的安裝說明,以及相關支援插件(Plug-in )的簡單介紹。

YOURLS 縮址服務伺服器可以安裝在共享型伺服器(Shred Server)、虛擬專用伺服器(Virtual Private Server)和專用伺服器下(Dedicated Server)下。

然而,由於有大量惡意程式會試圖利用你的服務,如果你打算開放公眾使用的話,可以假設在獨立伺服器作為專用,尋找最便宜的共享型伺服器就是不錯的選擇。

如何架設 YOURLS 縮址服務

首先,你必須擁有一個 Apache / Nginx 網頁伺服器,我推薦可以在「Bluehost」購得,買最便宜的就好,除非你打算開放給幾百幾萬人使用。

在「Yourls Download」下載最新版本的套件檔案(1.7.4),解壓縮存放到伺服器預設的網頁目錄下(例如 Apache 原始目錄位在 /var/www)。一般來說可以全部解壓縮到網頁原始目錄下,或是將所有檔案解壓縮網頁目錄下的套件資料夾後,再透過 .htaccess 指向該資料夾。

.htaccess 標準指令(指向網頁根目錄)

# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
</IfModule>
# END YOURLS / MOUNTOS : Institute

接著,進入解壓縮出來的 User 目錄,將 Config-Sample.php 修改成 config.php,並且「至少」修改下列四項架站最重要的基礎參數(需事先在伺服器架設好 MySQL 伺服器並且新增資料庫和使用者):

define( 'YOURLS_DB_USER', 'DB_USERNAME' ); //資料庫的使用者名稱
define( 'YOURLS_DB_PASS', 'DB_PASSWORD' ); //資料庫的密碼
define( 'YOURLS_DB_NAME', 'DB_NAME' ); //資料庫的名稱
define( 'YOURLS_SITE', 'http://DOMAIN_NAME' ); //網站的域名

只要完成上述設定,第一次登入「http://DOMAIN_NAME」時會出現安裝說明頁面,只要點選畫面中的「Install」按鈕,Yourls 就會開始自動設定並進行安裝。

如果所有設定都正確,接著開啟「http://DOMAIN_NAME/admin」網址,就會進入如下圖一所示的 Yourls 控制後台管理介面。

Yourls 縮址服務管理介面。
圖一,Yourls 縮址服務管理介面。

在上圖一中,我們能發現管理介面是由左上方的「選單」、中間位置的「網址輸入」以及佔據畫面下面大部分空間的「網址對應列表」所組成,整體組成元素相當簡單清爽。

Yourls 快速加入工具(書籤按鈕)

Yourls 提供兩個工具,分別是「書籤按鈕」以及「網址前綴」,這是我認為比起 Goo.gl 來得更好用的原因(不需要靠瀏覽器的延伸工具)。

所謂書籤按鈕指的是如下圖二的書籤列上的那顆按鈕,只要在瀏覽網頁時點選該書籤按鈕,我們架設的縮址服務就會自動運作,並建立對應的縮網址。

縮址服務書籤按鈕。
圖二,縮址服務書籤按鈕。

最棒的建立這顆書籤按鈕非常簡單,只要進入 Yourls 縮網址服務的控制後台(http://YOUR-DOMAINNAME/admin/),點擊左上方選單的「Tools」選項,就能看到如下圖三所示的縮址工具列表。

YOURLS 書籤縮址工具。
圖三,YOURLS 書籤縮址工具。

另外,網址前綴的說明雖然也在同一個「Tools」頁面中,但是不需要特別設定就能直接使用。

使用方式是在一般正常網址前方(包括 http:// 或 https://),直接加上我們架設縮址服務的網址。正確網址範例如下:

https://oon.me/https://www.vedfolnir.com

Yourls 縮網址服務推薦插件:

Yourls 縮網址服務具有加強功能用的插件(Plugin)支援,在 Admin 管理頁面中,點選「Manage Plugins」選項進入插件管理頁面(如下圖四所示)。

每一項插件後方的「Action」欄位都能直接啟用(Activate)或關閉(Deactivate)該插件功能。

YOURLS 插件管理。
圖四,YOURLS 插件管理。

所有 Yourls 插件都被收錄在 GitHub 網站中,大家可以輕易在「Plugin List」列表中找到所需插件。下面七項是工具人逐一確認過後認為比較有用的幾個插件,有需要的人可以參考看看。

  • 302-instead:將縮網址轉址由 301 改為 302 轉址(避免 SEO 權重被分散)。
  • Mass Remove Link:可使用條件(日期、IP位址)大量刪除縮網址。
  • multi-user-yourls:可自由新增使用者(我自己沒試過,不過看起來蠻有用,做個紀錄)。
  • Qrcode Plugin for Yourls(或 Qr Google Charts):縮短長網址時順便產生 QR Code。
  • Random Keywords:這是我個人極度推薦的插件,可以亂數產生縮網址代碼(原始程式只會從 1 開始往下數)。
  • Yourls-Memcached:適用多網站伺服器,可減輕硬體負擔(未用過)。
  • Upload and Shorten:可以在 Yourls 後台上傳檔案,並生成對應的縮網址,相當有趣的應用。

安裝 Yourls 插件的說明

上一階段提到啟用與關閉插件的方法,但是要如何新增插件呢?

新增插件的第一步,我們需要進入伺服器,找出文章前面提到安裝 Yourls 縮址服務的網頁目錄(例如 Apache 原始目錄位在 /var/www)。

第二步,進入該目錄下的 user 資料夾,再進入 plugin 資料夾。plugin 資料夾中存放所有插件所需的檔案。

第三步,在 plugin 資料夾下,新建一個資料夾(指令:sudo mkdir FOLDER_NAME),資料夾名稱請直接填寫插件名稱即可。

第四步,進入新建的資料夾,建立一個名為 plugin.php 的文件檔(指令:sudo nano plugin.php)。

第五步,從上一階段介紹的「Plugin List」插件列表中,找到符合自己所功能的插件。接著點開該插件連結,將網頁上顯示的 plugin.php 程式碼直接複製貼上我們在第四步中新建的 plugin.php,就可以儲存後離開。

第六步,回到 Yourls 控制後台的插件管理,這時候應該就能看見新增的插件,只要直接啟用該插件就能正常使用新服務。

使用 Yourls 自架縮網址服務的壞處

前面提到自架縮網址服務有許多好處(至少心裡爽度),但是壞處也不少。因為多了一項網路服務代表被惡意騷擾的機會也大。

以 Yourls 來說,可以將縮址服務採用用戶登入方式進行作業,也可在 /user/config.php 中把隱私保護關閉。但是一旦將縮址服務公開在網路上,緊接而來的就是大量病毒程式會自動申請短網址。而且不管裝了哪一套防止攻擊的插件都無法阻止這些惡意侵害,加上大量註冊短網址也意味著伺服器處理程序會被佔用,進而影響伺服器效能。

另外,許多插件已經是多年前釋放出來(看過最久的是五年),有些插件功能已經被新版 Yourls 內化,有些則是一點用處都沒有。請謹慎評估自己需要的插件功能。

2016.02.01 補充:使用 Yourls 需要小心設定 Apache Web Server,使用太先進 Web Template(例如:phpfcgid)時可能會陷入無限循環的錯誤中(例如一直要你重新 Install),目前錯誤的原因不清楚,但只要分開設定不同的 Web Template 即可。另外,如果後來才設定 php.ini 也可能導致錯誤(暫時抓不到bug)。

延伸閱讀/附錄:

  1. 專業伺服器供應商推薦:Bluehost(推薦度:★★★★★)。
  2. 專業域名、伺服器供應商:Namecheap(★★★★)。
  3. 官方網站:YOURLS

使用 Email 訂閱 最新消息不漏接

我們尊重您的隱私,隨時可取消訂閱。

留言

在〈YOURLS 短網址系統安裝教學(類似Bit.ly縮址應用)〉中有 23 則留言

  1. 「Claudette Summers」的個人頭像
    Claudette Summers

    I love reading through an article that can make men and women think. Also, many thanks for permitting me to comment!

  2. 「Laverne Albright」的個人頭像
    Laverne Albright

    Nice post. I was checking constantly this weblog and I am impressed! Extremely helpful info particularly the last section :) I deal with such info much. I used to be seeking this certain info for a long time. Thanks and best of luck.

  3. 「Kassie Arrowood」的個人頭像
    Kassie Arrowood

    I love your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz reply as I’m looking to create my own blog and would like to find out where u got this from. thanks

  4. 「Phillip Frazer」的個人頭像
    Phillip Frazer

    I got this website from my buddy who shared with me concerning this web page and now this time I am browsing this website and reading very informative content here.

  5. 「Kristofer Autry」的個人頭像
    Kristofer Autry

    I enjoy, cause I discovered exactly what I was taking a look for. You’ve ended my 4 day long hunt! God Bless you man. Have a great day. Bye

  6. 「Poppy Farris」的個人頭像
    Poppy Farris

    Saved as a favorite, I like your website!

  7. 「Jack Reade」的個人頭像
    Jack Reade

    Ԝith todays rising gas costs everything just ѕeems to ɡet a bit mοre expensive еach day. Υou understand that each penny saved can help ᴡhen you personal ɑn organization.

  8. 「Clint Pietrzak」的個人頭像
    Clint Pietrzak

    Link exchange is nothing else except it is only placing the other person’s website link on your page at appropriate place and other person will also do same in support of you.

  9. 「Kelley Presley」的個人頭像
    Kelley Presley

    I really like your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz respond as I’m looking to design my own blog and would like to find out where u got this from. many thanks

  10. 「Zoe Alden」的個人頭像
    Zoe Alden

    This paragraph is truly a good one it helps new the web users, who are wishing for blogging.

  11. 「Keesha Rapp」的個人頭像
    Keesha Rapp

    I’m really enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your theme? Great work!

  12. 「Madonna Nielsen」的個人頭像
    Madonna Nielsen

    Hi there are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you need any html coding knowledge to make your own blog? Any help would be really appreciated!

  13. 「Laurinda Rosenberger」的個人頭像
    Laurinda Rosenberger

    Great article, totally what I wanted to find.

  14. 「Dorris Perdue」的個人頭像
    Dorris Perdue

    This is my first time go to see at here and i am truly impressed to read everthing at single place.

  15. 「Francine Huston」的個人頭像
    Francine Huston

    great put up, very informative. I’m wondering why the opposite experts of this sector do not realize this. You should continue your writing. I am sure, you have a huge readers’ base already!

  16. 「Katherin Godinez」的個人頭像
    Katherin Godinez

    I loved this message! I review your blog relatively usually as well as you’re always bring out some fantastic things. I shared this on my facebbok and my followers enjoyed it! Maintain the good work :)

  17. 「Paulette Little」的個人頭像
    Paulette Little

    Truly when someone doesn’t understand after that its up to other visitors that they will help, so here it takes place.

  18. 「Vanessa Bateson」的個人頭像
    Vanessa Bateson

    Just wish to say your article is as amazing. The clarity in your post is simply nice and i could assume you are an expert on this subject. Fine with your permission let me to grab your RSS feed to keep updated with forthcoming post. Thanks a million and please continue the rewarding work.

  19. 「Jessie Hartman」的個人頭像
    Jessie Hartman

    Pretty! This has been a really wonderful article. Thanks for supplying this info.

  20. 「Vida Dolling」的個人頭像
    Vida Dolling

    Great post. I was checking constantly this weblog and I am impressed! Extremely helpful information specially the remaining section :) I care for such information much. I used to be seeking this particular info for a long time. Thanks and best of luck.

  21. 「Anastasia Gillum」的個人頭像
    Anastasia Gillum

    Pretty section of content. I just stumbled upon your blog and in accession capital to assert that I get in fact enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently rapidly.

  22. 「Effie McDonagh」的個人頭像
    Effie McDonagh

    Thank you for sharing your info. I really appreciate your efforts and I will be waiting for your next write ups thanks once again.

  23. 「Adrianna Conlon」的個人頭像
    Adrianna Conlon

    Thanks in support of sharing such a good opinion, piece of writing is fastidious, thats why i have read it entirely

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *