wsgi

使用wsgiref库diy简单web架构

不问归期 提交于 2020-01-18 19:54:10
1. 了解CGI和WSGI (1)CGI   CGI(Common Gateway Interface)通用网关接口,即接口协议,前端向服务器发送一个URL(携带请求类型、参数、cookie等信息)请求,服务器把这个请求的各种参数写进进程的环境变量,比如 REQUEST_METHOD,PATH_INFO之类的,然后开启 cgi模块以后,将其发送给CGI程序,CGI程序(可以由各种语言编写,比如C、C ++、VB 和Delphi 等)从环境变量中解析出各种参数,然后向标准输出输出内容(比如cout了一段HTML代码),这些内容没有被打印到控制台上,而是最终响应给了你的浏览器,渲染出了网页。每一次向CGI发送请求,都会生成一个CGI进程,这就是所谓的fork-and-exec模式,这也通常是导致并发瓶颈的症结,反向代理加上大型的的分布式系统可以一定程度上减轻这些压力。 (2)WSGI   WSGI(Python Web Server Gateway Interface,缩写为WSGI)web服务器网关接口,也是接口协议,前端向服务器发送一个URL(携带请求类型、参数、cookie等信息)请求,服务器把这个请求的各种参数传给WSGI模块,wsgi将各种参数进行python化,封装为request对象传递给按照WSGI接口标准调用注册的WSGI Application

ubuntu python apache2 wsgi django框架

独自空忆成欢 提交于 2020-01-18 08:00:37
在ubuntu上通过apatch2和wsgi部署django (亲手做过!!!) 一,我的python、django、apatch2版本: python:python -V   2.7.3 django:python -c "import django; print(django.VERSION)"   (1, 9, 4, 'final', 0) apache2:/usr/sbin/apachectl -v   Server version: Apache/2.2.22 (Ubuntu)   Server built: Jul 24 2015 17:25:52 二,安装python 和django。 三,安装apache2 和 wsgi。 sudo apt-get insall apache2 sudo apt-get install libapache2-mod-wsgi 如果之前安装配置过apache2的并且配置很乱,无法修复,建议还是完全卸载之后再安装。完全卸载的命令: sudo apt-get --purge remove apache* sudo apt-get --purge remove apache-common 安装完以后,去 /etc/apache2/ 下的 mods-available 和mods-enabled 中查看是否都存在 wsgi.conf

Does teardown_appcontext ignore HTTPExceptions?

梦想与她 提交于 2020-01-16 18:26:32
问题 So, I'm trying to rollback the database session in case of an HTTP error like a bad_request, unauthorized, forbidden, or not_found happens. it is a serverless application with wsgi and flask. The scenario is: I create an entry to be saved in the database, but if something wrong happens, I want it to roll_back the session. If, I raise an exception, the rollback happens, but if I use abort(make_response(jsonify(message=message, **kwargs), 400)) an HTTPException is raised, but the teardown

apache+mod_wsgi配置

那年仲夏 提交于 2020-01-15 02:33:45
apache+mod_wsgi配置 - Healich - ITeye技术网站 apache+mod_wsgi配置 博客分类: Python Apache Python Django Google 脚本 在apache下配置mod_wsgi Apache http Server: http://httpd.apache.org/ modwsgi: http://code.google.com/p/modwsgi/ , http://code.google.com/p/modwsgi/wiki/InstallationInstructions WSGI: http://www.python.org/dev/peps/pep-0333/ 在安装好apache之后,还需要下载mod_wsgi.mod_wsgi是用于apache支持python wsgi协议的扩展,当前版本是3.3,有windows下支持不同python版本的二进制文件下载。 首先需要使apache httpd服务器加载wsgi_module扩展。将下载的mod_wsgi.so置于apache serverr安装目录的modules文件下,在httpd.conf文件中添加如下一行: Java代码 LoadModule wsgi_module modules/mod_wsgi.so LoadModule wsgi

Ubuntu16.04 apache2 wsgi 部署django

我的未来我决定 提交于 2020-01-15 02:28:57
在Ubuntu16.04上部署django其实还算简单直观,最重要的问题就是路径设置正确,并且保证版本统一,这个测试是在 Apache/2.4.18 (Ubuntu) apt-get install apache2 Python/2.7.11 wget https://www.python.org/ftp/python/2.7. 1 1 /Python-2.7. 1 1 .tar.xz mod_wsgi/4.3.0 apt-get install libapache2-mod-wsgi 一,安装python 和django。这个很简单,django用pip安装就可以。就不解释了。 二,安装apache2 和 wsgi。 这里用的是apt-get. sudo apt-get install apache2 sudo apt-get install libapache2-mod-wsgi 需要注意的是,如果之前安装配置过apache2的并且配置很乱,无法修复,建议还是完全卸载之后在安装。完全卸载的命令: $ sudo apt-get --purge remove apache-common $ sudo apt-get --purge remove apache* 安装完以后,去 /etc/apache2/ 下的 mods-available 和mods-enabled

ubuntu12.04 server + apache2 + wsgi + django1.6 部署

南笙酒味 提交于 2020-01-14 23:26:33
最近在学Python和Django,想自己部署一个服务器试试 环境:ubuntu12.04 server | apache2 | django1.6 | python2.7 | mod_wsgi 在网上找了好多参考都不起作用,不是老版本的方法就是过于复杂 今天柳暗花明又一村,在Django官网(djangoproject.com)上找到了最简单的方法: 1. 安装apache2: sudo apt-get install apache2 apache2相关的操作: 启动:sudo service apache2 start 停止:sudo service apache2 stop 重启:sudo service apache2 restart(更改配置后的常用操作) 启动测试:在浏览器中输入http://localhost 配置文件的位置: 可执行程序:/usr/sbin/apache2 配置文件:/etc/apache2 网站文件:/var/www (网站的默认位置可以在/etc/apache2/sites-available/default中更改,修改DocumentRoot /var/www改成自己的网站存放地址即可) apache2主要配置为/etc/apache2/apache2.conf,但是并没有配置所有的东西,端口配置在ports.conf,网站根目录在/etc

Handling HTTP chunked encoding with django

孤街浪徒 提交于 2020-01-12 05:35:12
问题 I have a problem handeling http chunked transfer encoding. I'm using: apache. mod_wsgi plugin. django. django, is only capable of handling reqular http request with content-length header field, but when it comes to handling TE (Transfer-Encoding), chunked or gzip, it returns an empty result. I'm thinking of 2 approaches: Making some modification to django.wsgi python file Add some middleware python file to django, to intercept any chunked http request,convert it to requelar http request with

Python, WSGI, multiprocessing and shared data

岁酱吖の 提交于 2020-01-11 15:20:30
问题 I am a bit confused about multiproessing feature of mod_wsgi and about a general design of WSGI applications that would be executed on WSGI servers with multiprocessing ability. Consider the following directive: WSGIDaemonProcess example processes=5 threads=1 If I understand correctly, mod_wsgi will spawn 5 Python (e.g. CPython) processes and any of these processes can receive a request from a user. The documentation says that: Where shared data needs to be visible to all application

Error while deploying flask app on apache

笑着哭i 提交于 2020-01-07 08:23:15
问题 I have a file manage.py, import os from app import create_app app = create_app(os.getenv('FLASK_CONFIG') or 'default') if __name__ == '__main__': app.run() manage.py is working fine when tested in debug mode. However, I'm not able to host it on apache. my wsgi file: start.wsgi from manage import app as application import sys sys.stdout = sys.stderr virtual host: <VirtualHost *:80> ServerName domain.com WSGIDaemonProcess manage user=user group=user threads=5 WSGIScriptAlias / /var/www

Apache 2.4 Error Log entries incomplete

末鹿安然 提交于 2020-01-07 03:46:08
问题 I am trying to configure Apache 2.4 to include log ID (%L) and remote client IP(%a) into the error.log entries so that I can correlate log entries from multiple log files. It works for every log entry, but not for the most important one - mod_wsgi (my Django app) This is the logging conf. from Virtual Host LogLevel debug ErrorLogFormat "[LogID %-L] [Remote IP %-a] [%-m:%l] [pid %P:tid %T] %M% ,\ referer\ %{Referer}i" ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log