Skip to content

Commit

Permalink
重构为 OpenResty 目录结构
Browse files Browse the repository at this point in the history
重新组织项目目录结构,按照标准 OpenResty 目录结构放置文件和代码
更新安装说明
  • Loading branch information
xiaooloong committed Sep 10, 2016
1 parent fbb10dc commit 4b65b1e
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.so
*.o
lualib/ourl/config.lua
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# Ourls-Resty

[Ourls][1] 是由 [takashiki][2] 实现的一个基于发号和 hashid 的短网址服务。
受这个项目的启发,将此工程移植,使用 [OpenResty][3] 实现
受这个项目的启发,将此项目移植到 [OpenResty][3]

### 待增加的特性:

- 工程目录优化,以 OpenResty 目录结构为准
- Cache 支持

### 安装方法:

- 安装 openresty rpm 包(或手动编译,建议使用 --prefix=/usr/local/openresty)
- 安装 libidn-devel 库(yum install libidn-devel)
- 将原 openresty/nginx/conf 目录备份
- 将本工程解压到 openresty/nginx/conf 目录,执行 `install.sh`
- 修改 ourl/config.lua 中的数据库等配置
- 恢复 urls.sql 至 mysql/mariadb 数据库
- 进入 vhosts 目录,修改 ourl.conf 中的 server_name 为你自己的域名
- 启动 openresty
- 安装 openresty [预编译包][9][手动编译教程][10]
- 安装 gcc、make、libidn、libidn-devel (yum gcc make install libidn-devel)
- 将本工程解压到 openresty 目录,执行 `install.sh` (bash install.sh)
- 修改 lualib/ourl/config.lua 中的数据库配置、hashids 参数、可信代理的 cidr
- 恢复 urls.sql 至 mysql 或 mariadb 数据库
- 进入 nginx/conf 目录,根据自己的实际情况修改 (合并配置,修改 server_name …)
- 启动 openresty (service openresty start)

### 使用到的其他项目

Expand All @@ -34,4 +32,6 @@
[5]: https://github.com/APItools/router.lua
[6]: https://github.com/golgote/neturl
[7]: https://github.com/mah0x211/lua-idna
[8]: https://github.com/hamishforbes/lua-resty-iputils
[8]: https://github.com/hamishforbes/lua-resty-iputils
[9]: http://openresty.org/cn/rpm-packages.html
[10]: https://moonbingbing.gitbooks.io/openresty-best-practices/content/openresty/install_on_centos.html
File renamed without changes.
File renamed without changes.
16 changes: 10 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#/bin/sh
#/usr/bin/env bash
BASE=$(dirname $(readlink -f ${0}))
cp "${BASE}/ourl/config.sample.lua" "${BASE}/ourl/config.lua"
cd "${BASE}/lib/hashids" && make
cd "${BASE}/lib/idna" && make linux
mv "${BASE}/lib/idna/idna.so" "${BASE}"
cd ${BASE}
PLATFORM=$(uname -s)
case ${PLATFORM} in
Darwin) PLATFORM='macosx' ;;
FreeBSD) PLATFORM='bsd' ;;
*) PLATFORM='linux' ;;
esac
cp "${BASE}/lualib/ourl/config.sample.lua" "${BASE}/lualib/ourl/config.lua"
cd "${BASE}/lualib/hashids" && make
cd "${BASE}/idna" && make ${PLATFORM} && mv "${BASE}/idna/idna.so" "${BASE}/lualib" && cd ${BASE}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/hashids/init.lua → lualib/hashids/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local strcat = table.concat
local push = table.insert
local str_switch_pos

local ok, lib = pcall(require, "lib.hashids.clib");
local ok, lib = pcall(require, "hashids.clib");
if ok then
str_switch_pos = lib.str_switch_pos;
else
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions ourl/init.lua → lualib/ourl/init.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
local config = require 'ourl.config'
local router = require 'lib.router'
local hashid = require 'lib.hashids.init'
local neturl = require 'lib.net.url'
-- idna.so 必须在 lua_package_cpath 根目录下才能使用
local router = require 'router'
local hashid = require 'hashids'
local neturl = require 'net.url'
local idna = require 'idna'
local iputil = require 'lib.resty.iputils'
local iputil = require 'resty.iputils'
local json = require 'cjson'
local mysql = require 'resty.mysql'
local r_sha1 = require 'resty.sha1'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions nginx.conf → nginx/conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ http {
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

lua_package_path '/usr/local/openresty/nginx/conf/?.lua;;';
lua_package_cpath '/usr/local/openresty/nginx/conf/?.so;;';

include vhosts/*.conf;
}
4 changes: 2 additions & 2 deletions vhosts/ourl.conf → nginx/conf/vhosts/ourl.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
server {
listen 80;
server_name t.sicaudm.com;
root conf/ourl/public;
root html/ourl;
index index.html;

location / {
Expand All @@ -11,7 +11,7 @@ server {
internal;
default_type text/html;
content_by_lua_block {
local t = require 'ourl.init'
local t = require 'ourl'
t.run()
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4b65b1e

Please sign in to comment.