Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM openresty/openresty:centos

LABEL maintainer="hanxi <hanxi.info@gmail.com>"

RUN yum install -y mysql
RUN yum install -y libuuid-devel
RUN /usr/local/openresty/bin/opm get sumory/lor

ADD . /orchina
WORKDIR /orchina

ADD ./init.sh /
RUN chmod +x /init.sh

ADD ./entrypoint.sh /
RUN chmod +x /entrypoint.sh
CMD ["/entrypoint.sh"]

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
![首页](./docs/index.jpg)


### 采用 Docker 运行

```bash
$ docker-composer up --build -d
$ docker-compose run orchina /init.sh
```

### 安装

- 首先安装OpenResty和[lor](https://github.com/sumory/lor)框架,安装成功的标志是以下三个命令可以正常输出
Expand Down
154 changes: 77 additions & 77 deletions app/config/config.lua
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
return {
-- 白名单配置:不需要登录即可访问;除非要二次开发,否则不应更改
whitelist = {
"^/m1",
"^/m2",

"^/index$",
"^/ask$",
"^/share$",
"^/category/[0-9]+$",
"^/topics/all$",
"^/topic/[0-9]+/view$",
"^/topic/[0-9]+/query$",

"^/comments/all$",

"^/user/[0-9a-zA-Z-_]+/index$",
"^/user/[0-9a-zA-z-_]+/topics$",
"^/user/[0-9a-zA-z-_]+/collects$",
"^/user/[0-9a-zA-z-_]+/comments$",
"^/user/[0-9a-zA-z-_]+/follows$",
"^/user/[0-9a-zA-z-_]+/fans$",
"^/user/[0-9a-zA-z-_]+/hot_topics$",
"^/user/[0-9a-zA-z-_]+/like_topics$",
"^/auth/login$", -- login page
"^/auth/sign_up$", -- sign up page
"^/about$", -- about page
"^/error/$" -- error page
},

-- 静态模板配置,保持默认不修改即可
view_config = {
engine = "tmpl",
ext = "html",
views = "./app/views"
},


-- 分页时每页条数配置
page_config = {
index_topic_page_size = 10, -- 首页每页文章数
topic_comment_page_size = 20, -- 文章详情页每页评论数
notification_page_size = 10, -- 通知每页个数
},



-- ########################## 以下配置需要使用者自定义为本地需要的配置 ########################## --

-- 生成session的secret,请一定要修改此值为一复杂的字符串,用于加密session
session_secret = "12345678", -- lua-resty-string: salt must be 8 characters or nil

-- 用于存储密码的盐,请一定要修改此值, 一旦使用不能修改,用户也可自行实现其他密码方案
pwd_secret = "salt_secret_for_password",

-- mysql配置
mysql = {
timeout = 5000,
connect_config = {
host = "127.0.0.1",
port = 3306,
database = "blog",
user = "root",
password = "",
max_packet_size = 1024 * 1024
},
pool_config = {
max_idle_timeout = 20000, -- 20s
pool_size = 50 -- connection pool size
}
},

-- 上传文件配置,如上传的头像、文章中的图片等
upload_config = {
dir = "/data/openresty-china/static", -- 文件目录,修改此值时须同时修改nginx配置文件中的$static_files_path值
},
-- 白名单配置:不需要登录即可访问;除非要二次开发,否则不应更改
whitelist = {
"^/m1",
"^/m2",

"^/index$",
"^/ask$",
"^/share$",
"^/category/[0-9]+$",
"^/topics/all$",
"^/topic/[0-9]+/view$",
"^/topic/[0-9]+/query$",

"^/comments/all$",

"^/user/[0-9a-zA-Z-_]+/index$",
"^/user/[0-9a-zA-z-_]+/topics$",
"^/user/[0-9a-zA-z-_]+/collects$",
"^/user/[0-9a-zA-z-_]+/comments$",
"^/user/[0-9a-zA-z-_]+/follows$",
"^/user/[0-9a-zA-z-_]+/fans$",
"^/user/[0-9a-zA-z-_]+/hot_topics$",
"^/user/[0-9a-zA-z-_]+/like_topics$",

"^/auth/login$", -- login page
"^/auth/sign_up$", -- sign up page
"^/about$", -- about page
"^/error/$" -- error page
},

-- 静态模板配置,保持默认不修改即可
view_config = {
engine = "tmpl",
ext = "html",
views = "./app/views"
},


-- 分页时每页条数配置
page_config = {
index_topic_page_size = 10, -- 首页每页文章数
topic_comment_page_size = 20, -- 文章详情页每页评论数
notification_page_size = 10, -- 通知每页个数
},



-- ########################## 以下配置需要使用者自定义为本地需要的配置 ########################## --

-- 生成session的secret,请一定要修改此值为一复杂的字符串,用于加密session
session_secret = "12345678", -- lua-resty-string: salt must be 8 characters or nil

-- 用于存储密码的盐,请一定要修改此值, 一旦使用不能修改,用户也可自行实现其他密码方案
pwd_secret = "salt_secret_for_password",

-- mysql配置
mysql = {
timeout = 5000,
connect_config = {
host = "ormysql",
port = 3306,
database = "orchina",
user = "orchina",
password = "orchina",
max_packet_size = 1024 * 1024
},
pool_config = {
max_idle_timeout = 20000, -- 20s
pool_size = 50 -- connection pool size
}
},


-- 上传文件配置,如上传的头像、文章中的图片等
upload_config = {
dir = "/data/openresty-china/static", -- 文件目录,修改此值时须同时修改nginx配置文件中的$static_files_path值
},

}
13 changes: 8 additions & 5 deletions conf/nginx-dev.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#generated by `lor framework`

pid tmp/nginx.pid;
worker_processes 4;
events {
Expand All @@ -21,15 +21,18 @@ http {
lua_code_cache on; # set off for development; session will lost if set off.
#LUA_SHARED_DICT


server {
resolver local=on ipv6=off;
resolver_timeout 5s;

listen 8888;
#server_name openresty-china.com;
set $template_root '';

# 用户上传的静态文件目录
set $static_files_path "/data/openresty-china/static";

# 头像和文章、评论图片
location /static/avatar {
alias $static_files_path;
Expand All @@ -55,7 +58,7 @@ http {
alias ./app/static/libs;
}


# Access log with buffer, or disable it completetely if unneeded
access_log logs/dev-access.log combined buffer=16k;
# Error log
Expand All @@ -68,4 +71,4 @@ http {
}
}


13 changes: 8 additions & 5 deletions conf/nginx-prod.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#generated by `lor framework`

pid tmp/nginx.pid;
worker_processes 4;
events {
Expand All @@ -21,15 +21,18 @@ http {
lua_code_cache on; # set on @production
#LUA_SHARED_DICT


server {
resolver local=on ipv6=off;
resolver_timeout 5s;

listen 80;
#server_name openresty-china.com;
set $template_root '';

# 用户上传的静态文件目录
set $static_files_path "/data/openresty-china/static";

# 头像和文章、评论图片
location /static/avatar {
alias $static_files_path;
Expand All @@ -55,7 +58,7 @@ http {
alias ./app/static/libs;
}


# Access log with buffer, or disable it completetely if unneeded
access_log logs/prod-access.log combined buffer=16k;
# Error log
Expand All @@ -68,4 +71,4 @@ http {
}
}


28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '2'

services:
ormysql:
image: mysql:5
restart: always
container_name: ormysql
environment:
- MYSQL_ROOT_PASSWORD=ormysqlroot
- MYSQL_DATABASE=orchina
- MYSQL_USER=orchina
- MYSQL_PASSWORD=orchina
volumes:
- ../ormysql/:/var/lib/mysql

orchina:
build:
context: ./
dockerfile: Dockerfile
container_name: orchina
ports:
- "2606:8888"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ../upload:/data/openresty-china/static
- ../logs:/orchina/logs

9 changes: 9 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

if [ -z "$PROFILE" ];then
PROFILE="dev"
fi

mkdir -p logs & mkdir -p tmp
echo "Use profile: "${PROFILE}
nginx -p `pwd`/ -c conf/nginx-${PROFILE}.conf -g 'daemon off;'
11 changes: 11 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

# usage
# docker-compose run orchina /init.sh

# import sql
mysql -h ormysql -u orchina -porchina -D orchina < /orchina/install/blog.sql

# copy avatar
cp /orchina/install/avatar/* /data/openresty-china/static/