推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
creatorYC
V2EX  ›  Python

Python 编写的 webservice 怎么部署到服务器(比如 Apache 等)上?

  •  
  •   creatorYC ·
    creatorYC · Aug 16, 2017 · 7720 views
    This topic created in 3218 days ago, the information mentioned may be changed or developed.

    使用 Python 的 spyne 库编写了 webservice 程序,在 PyCharm 里面运行着,就是这样启动的:

    if __name__ == '__main__':
        server = make_server(ip, port, wsgi_app)
        server.serve_forever()
    

    现在想把这个 webservice 部署到服务器上,应该怎么配置啊?可以放到 Apache 这样的服务器上吗?在网上搜了一圈实在没找到解决方案,特来请教。

    13 replies    2017-08-17 01:07:52 +08:00
    Geoion
        1
    Geoion  
       Aug 16, 2017
    能持久化就行,supervisor 一把梭
    hcymk2
        2
    hcymk2  
       Aug 16, 2017
    我看到了 wsgi
    creatorYC
        3
    creatorYC  
    OP
       Aug 16, 2017
    @Geoion 能不能详细说说啊,囧
    creatorYC
        4
    creatorYC  
    OP
       Aug 16, 2017
    @hcymk2 它不该出现吗?哈哈
    gemini
        5
    gemini  
       Aug 16, 2017
    搜搜 nginx + python + uwsgi 大把
    比如 http://www.cnblogs.com/Erick-L/p/7066455.html
    hifans
        6
    hifans  
       Aug 16, 2017
    windows 上我用 apache
    linux 直接上 gunicorn
    chaleaoch
        7
    chaleaoch  
       Aug 16, 2017
    你自己写了 一个 server,然后还要部署到 server 上?
    你的意思是前面在架一个 nginx 做分发吗?

    我没太理解。。。
    codeface
        8
    codeface  
       Aug 16, 2017
    uwsgi 或者 反向代理
    creatorYC
        9
    creatorYC  
    OP
       Aug 16, 2017
    @chaleaoch 自己写了一个 webservice 接收请求返回数据,想让他运行在 apache 上,现在是在 pycharm 里运行的
    creatorYC
        10
    creatorYC  
    OP
       Aug 16, 2017
    @hifans windows 上 apache 我不太清楚怎么配置,以前部署过 Django 程序,跟那差不多配置吗
    fffflyfish
        11
    fffflyfish  
       Aug 16, 2017
    最简单的方法就是端口反向代理
    chaleaoch
        12
    chaleaoch  
       Aug 16, 2017
    @creatorYC 我说一下我的理解不一定对。

    我感觉你现在做的相当于自己实现了一个简易版的 apache,但是你现在想让一个 apache 运行的 apache 上。。。好奇怪。。。

    你说的 webservice 是指 wsgi_app 还是 make_server。
    dangyuluo
        13
    dangyuluo  
       Aug 17, 2017
    Apache 是一个服务器软件,你写的 Python 实现了部分 Apache 的功能,二者在同一级别上,怎么说谁部署到谁?
    我觉得你可以这样,Apache 监听 80 端口,python 脚本监听 8080 端口。根据 ip 或者域名,在 apache 里用 reverse proxy 代理 8080 端口。这样你既可以将你的软件发布到 web,又可以使用 apache 比较强大的目录管理与插件功能。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5663 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 01:37 · PVG 09:37 · LAX 18:37 · JFK 21:37
    ♥ Do have faith in what you're doing.