flask项目部署到云服务器,并通过域名访问后端服务
本篇介绍一下如何把flask项目部署到腾讯云服务器,同时使用域名来访问后端服务
在之前一篇文章中写了一下如何在flask中配置https请求
1、把代码打包上传到服务器
上传至服务器前,需要修改一下启动ip
我的项目启动文件为run_main.py
from data_factory import create_app
app = create_app()
if __name__ == '__main__':
# app.run(debug=True, host='0.0.0.0', port=5000)
app.run(debug=True, host='10.xxx.xxx.xxx', port=5000, ssl_context=('7784675_bingshuang.top.pem','7784675_bingshuang.top.key'))
因为要部署到云服务器,所以host
需要改为云服务器地址
注意这里不要改为公网ip,要填写内网ip!!
然后把代码上传到服务器,如下
2、域名设置
给域名配置ip地址,这里需要写入服务器的公网ip
3、启动项目
在云服务器中启动flask项目,命令如下
# 首先进入项目目录,然后运行run_main.py
[root@VM-8-3-centos flaskProject]# cd /app/flaskProject/
[root@VM-8-3-centos flaskProject]# python3 run_main.py
/usr/local/lib/python3.6/site-packages/pymysql/_auth.py:8: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
from cryptography.hazmat.backends import default_backend
* Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
* Serving Flask app "data_factory" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on https://11.1.2.3:5000/ (Press CTRL+C to quit)
* Restarting with stat
/usr/local/lib/python3.6/site-packages/pymysql/_auth.py:8: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
from cryptography.hazmat.backends import default_backend
* Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
* Debugger is active!
* Debugger PIN: 145-638-942
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具