CNCityRisk-web 是一个用于展示城市风险评估结果的 Web 应用程序,使用 Flask 框架构建。
- 克隆仓库:
git clone https://github.com/youtian95/CNCityRisk-web.git
- 使用conda创建虚拟环境并激活:
source ~/.bashrc cd CNCityRisk-web conda create -p ./env python=3.11 conda activate ./env
- 将安装包
cncityrisk-0.1.0-py3-none-any.whl
上传到当前目录。 - 安装依赖(GDAL用
pip install
会报错,所以先安装好):conda install -c conda-forge GDAL=3.7.3 pip install cncityrisk-0.1.0-py3-none-any.whl pip install -r requirements.txt
- 将
maps.7z
损失图结果数据文件上传到~/CNCityRisk-web/CNCityRiskWeb/static/maps
目录下。 - 修改
~/CNCityRisk-web/.flaskenv
:修改为:vim ./.flaskenv
FLASK_ENV=production FLASK_DEBUG=FALSE ...
- 添加
config.ini
文件:添加以下内容:vim config.ini
[API] api_key_OpenTopography = your_key api_key_TDT = your_key
Gunicorn 是一个 WSGI 服务器,用于运行 Flask 应用,并将其作为后台服务。
- 安装 Gunicorn
pip install gunicorn
- 运行 Flask 应用(
&
在后台运行):gunicorn -w 4 -b 0.0.0.0:8000 wsgi:app &
将所有来自外部的请求转发到 Gunicorn 来处理。
-
安装 Nginx:
sudo apt-get install nginx
-
创建 Nginx 配置文件:
sudo vim /etc/nginx/sites-available/cncityrisk-web
添加以下内容:
server { listen 80; server_name your_domain_or_IP; # 替换为你的域名或服务器的IP location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
-
使用符号链接将配置文件链接到 sites-enabled:
sudo ln -s /etc/nginx/sites-available/cncityrisk-web /etc/nginx/sites-enabled
-
启用配置并重启 Nginx:
sudo systemctl restart nginx
在浏览器中打开 http://your_domain_or_IP
查看应用程序。
-
拉取最新代码:
cd ~/CNCityRisk-web git pull
-
上传建筑数据文件
.\CNCityRisk\Data\BldData\
到cncityrisk
包中的相应位置,上传地图数据文件CNCityRisk-web\CNCityRiskWeb\static\maps\maps.7z
,上传安装包cncityrisk-0.1.0-py3-none-any.whl
-
更新依赖:
pip install cncityrisk-0.1.0-py3-none-any.whl pip install -r requirements.txt
-
重启 Gunicorn 服务:
sudo systemctl restart gunicorn
-
重启 Nginx 服务:
sudo systemctl restart nginx