• 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
  • 相关阅读:
    (转)python编写登录接口
    (转)Python之文件读写
    (转)python strip()函数 去空格 函数的用法
    (转)模块readline解析
    (转)跟着老男孩一步步学习Shell高级编程实战
    图片服务器优化 解决流量和存储问题
    某大型网站图片服务器改造方案
    雅虎网页优化14条原则
    独立的图片服务器架构
    城市分站设计思路
  • 原文地址:https://www.cnblogs.com/hanmk/p/16408482.html
Copyright © 2020-2023  润新知