|
1 | 1 | [](https://www.python.org/downloads/release/python-360/) |
2 | 2 |
|
3 | | -NKUST-AP-API |
| 3 | + |
| 4 | + NKUST API Server(高雄科技大學 API Server) |
4 | 5 | ========== |
| 6 | +* [Requirement](#requirement) |
| 7 | +* [API Docs](#api-docs) |
| 8 | +* [Quick start](#quick-start) |
| 9 | + * [Using Python virtual enviroment & Gunicorn](#using-python-virtual-enviroment-&-gunicorn) |
| 10 | + * [Using Docker-compose](#using-docker-compose) |
| 11 | + |
5 | 12 |
|
6 | | -高雄科技大學 API Server NKUST API Server |
7 | | ---------------------------- |
8 | 13 | Requirement |
9 | 14 | --- |
10 | 15 | - Ubuntu (18.04 or previous version) |
11 | 16 | - Python 3.6 |
12 | 17 | - Redis server |
13 | 18 | - NodeJS (if host by python venv) |
14 | 19 |
|
15 | | -API Docs |
| 20 | +### [API Docs](https://github.com/NKUST-ITC/NKUST-AP-API/tree/gh-pages/docs) |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +Quick start |
16 | 25 | --- |
17 | | -[API PAGE](https://nkust-itc.github.io/NKUST-AP-API/docs/api-page.html) |
| 26 | +### Using Python virtual enviroment & Gunicorn |
| 27 | + |
| 28 | +需要先在本地端設定/安裝好 [Redis server](https://redis.io/) |
| 29 | + |
| 30 | +如果Redis有自行調整Host或Port或是使用外部的Redis,需執行 |
| 31 | + |
| 32 | +預設為本地的位置 `redis://127.0.0.1:6379` 執行 |
| 33 | + |
| 34 | +```bash |
| 35 | +$ export REDIS_URL=redis://127.0.0.1:6666 |
| 36 | +``` |
| 37 | + |
| 38 | +若設定最新消息的管理員,可以透過`;`來新增多位管理員(非必須) |
| 39 | + |
| 40 | +```bash |
| 41 | +$ export NEWS_ADMIN="1106111111;1105293392" |
| 42 | +``` |
| 43 | + |
| 44 | +或是設定一個帳號密碼,來登入管理員。 |
| 45 | + |
| 46 | +```bash |
| 47 | +$ export NEWS_ADMIN_ACCOUNT="admin" |
| 48 | +$ export NEWS_ADMIN_PASSWORD="1234567" |
| 49 | +``` |
| 50 | + |
| 51 | +創建Python virtual enviroment |
18 | 52 |
|
19 | | -[docs](https://github.com/NKUST-ITC/AP-API/tree/develop/docs/v3) |
| 53 | +```bash |
| 54 | +$ python3 -m venv venv |
| 55 | +``` |
| 56 | + |
| 57 | +啟動 virtual enviroment |
| 58 | + |
| 59 | +```bash |
| 60 | +$ source venv/bin/activate |
| 61 | +``` |
| 62 | + |
| 63 | +安裝相關packages |
| 64 | + |
| 65 | +```bash |
| 66 | +$ pip3 install -r requirement.txt |
| 67 | +``` |
| 68 | + |
| 69 | +啟動伺服器(Debug 模式) |
| 70 | + |
| 71 | +```bash |
| 72 | +$ gunicorn web-server:app |
| 73 | +``` |
| 74 | + |
| 75 | +啟動伺服器(Release 模式) |
| 76 | + |
| 77 | +```bash |
| 78 | +$ gunicorn -c gunicorn_config.py web-server:app |
| 79 | +``` |
20 | 80 |
|
21 | | -Donate |
22 | 81 | --- |
23 | | -[](https://coinbase.com/checkouts/aa7cf80a2a85b4906cb98fc7b2aad5c5 "Donate |
25 | | -once-off to this project using BitCoin") |
26 | 82 |
|
27 | 83 |
|
| 84 | + |
| 85 | +### Using Docker-compose (Production Stage) |
| 86 | + |
| 87 | +#### docker-compose中的docker image |
| 88 | + |
| 89 | +* [NKUST-AP-API](https://cloud.docker.com/u/nkustitc/repository/docker/nkustitc/nkust-ap-api/general) |
| 90 | +* Redis |
| 91 | +* Nginx |
| 92 | +* Certbot |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +```bash |
| 97 | +$ cp env.example .env |
| 98 | +``` |
| 99 | + |
| 100 | +如果有要設定`最新消息`的管理者,可以在`.env`中修改 `NEWS_ADMIN` 參數 |
| 101 | + |
| 102 | +``` |
| 103 | +REDIS_URL=redis://redis:6379 |
| 104 | +``` |
| 105 | + |
| 106 | +如需要更改redis位置,可以在`.env`中修改 `REDIS_URL` 參數, |
| 107 | + |
| 108 | +**這邊redis中的host是套用 `dokcer network` 的設定** |
| 109 | + |
| 110 | +``` |
| 111 | +REDIS_URL=redis://redis:6379 |
| 112 | +``` |
| 113 | + |
| 114 | +複製 nginx 設定檔(HTTPS) |
| 115 | + |
| 116 | +```bash |
| 117 | +$ cp nginx/nginx_nkust_api.conf.Example nginx/nginx_nkust_api.conf |
| 118 | +``` |
| 119 | + |
| 120 | +若需要單純使用 HTTP 則需複製 `nginx_nkust_api_http.conf.Example` |
| 121 | + |
| 122 | +```bash |
| 123 | +$ cp nginx/nginx_nkust_api_http.conf.Example nginx/nginx_nkust_api.conf |
| 124 | +``` |
| 125 | + |
| 126 | +將`nginx_nkust_api_http.conf` 設定檔中 "**所有**"`example.org`取代為要目標的網域 |
| 127 | + |
| 128 | +``` |
| 129 | +2 server_name example.org; |
| 130 | +... |
| 131 | +17 server_name example.org; |
| 132 | +``` |
| 133 | +更改為 |
| 134 | +``` |
| 135 | +2 server_name 目標網域; |
| 136 | +... |
| 137 | +17 server_name 目標網域; |
| 138 | +``` |
| 139 | + |
| 140 | +### 註冊SSL憑證 |
| 141 | + |
| 142 | +修改`init-letsencrypt.sh` `line 8~9` 中的網域及email |
| 143 | + |
| 144 | +```bash |
| 145 | +8 domains=(aaa.example.org aaa.example.org) |
| 146 | +9 email="aaaa@example.org" |
| 147 | +``` |
| 148 | + |
| 149 | +給予shell sript 權限 |
| 150 | + |
| 151 | +```bash |
| 152 | +$ sudo chmod +x init-letsencrypt.sh |
| 153 | +``` |
| 154 | + |
| 155 | +並執行shell sript註冊,此過程會開啟伺服器 |
| 156 | + |
| 157 | +```bash |
| 158 | +$ sudo ./init-letsencrypt.sh |
| 159 | +``` |
| 160 | + |
| 161 | +後續再次開啟**不需要**使用`init-letsencrypt.sh` |
| 162 | + |
| 163 | +最後執行docker-compose 開啟伺服器 |
| 164 | + |
| 165 | +-d 為背景執行,若不需要可以不用加 |
| 166 | + |
| 167 | +```bash |
| 168 | +$ docker-compose up -d |
| 169 | +``` |
| 170 | + |
| 171 | +#### Other port |
| 172 | + |
| 173 | +如有其他port 的需求 |
| 174 | + |
| 175 | +修改`nginx/nginx_nkust_api.conf` 像是一般的nginx設定檔案 |
0 commit comments