Articles of python

如何在Nginx下安装ReviewBoard?

对不起,我可怜的英语,我是法语…没有人是完美的。 我试图在Nginx下安装ReviewBoard(LEMP与Debian Wheezy,Nginx 1.4.5,MySQL 14.14,PHP 5.4.4)。 我的python安装使用Python 2.7.3,easy_install 0.6.24dev-r0,pip 1.1,virtualenv 1.11.4和gunicorn 18.0。 我成功安装了所有这些东西,并创build了一个评论板网站,但是我无法从浏览器访问评论版网站。 我知道评论板推荐Apache,但也可以将其安装在Nginx上。 除了很多指向http://rramsden.ca/blog/2011/09/26/nginx-reviewboard/的链接之外,我找不到任何分步教程,但是此链接已经死亡。 有谁知道另一个链接? 我的Nginx conf是: server { listen 80; server_name review.unskontrollables.org; root /var/www/review.unskontrollables.org/htdocs; # Error handlers error_page 500 502 503 504 /errordocs/500.html; # serve directly – analogous for static/staticfiles # Alias static media requests to filesystem location /media { alias /var/www/review.unskontrollables.org/htdocs/media; # […]

NGINX + webapp2 + Python的问题

我一直在研究很久,但我看不到webapp2如何在Google App Engine (“GAE”)之外工作(与NGINX结合)。 我真的很喜欢webapp2 ,即使我可以用python script.py来运行它,我们如何将python传递给webapp2 ,其余的传递给NGINX ? TL; DR – 您如何使NGINX尽可能接近GAE架构? 我觉得GAE非常愉快,但这不符合我的需要。 太多限制。

如何使用nginx auth_request模块+ python授权访问目录

我想授权访问目录/private使用auth_request Nginx模块。 在Nginx的文档中 ,似乎我应该像下面这样做: server { listen 80; server_name localhost; location /private/{ auth_request /auth; } location /auth { proxy_pass http://localhost:8080/; proxy_pass_request_body off; proxy_set_header Content-Length ""; proxy_set_header X-Original-URI $request_uri; } } 在我的情况下, http://localhost:8080/是一个python服务器,它应该根据数据库对用户进行身份validation。 这里是python代码: import tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): def post(self): print(str(self.request)) raise tornado.web.HTTPError(403) # just test def get(self): print(str(self.request)) raise tornado.web.HTTPError(401) # test also […]

uwsgi_response_write_body_do()TIMEOUT – 但是uwsgi_read_timeout没有帮助(x-post)

我在与Nginx进行交互时遇到了这个错误: uwsgi_response_write_body_do() TIMEOUT !!! IOError: write error 它一般工作正常。 这只发生在我用50个并发连接进行testing时发生了一个发送200MB数据的方法。 我一直在寻找所有,但我看到build议增加uwsgi_read_timeout 🙁 (我在uwsgi github页面上问过,但是我在想,因为这可能不是一个错误,所以最好在这里问) 以下是我如何启动uwsgi: flask/bin/uwsgi -s 127.0.0.1:9001 –need-app –wsgi-file app.py –processes 1 –callable app –daemonize /opt/logs/KVAutobus-uwsgi_01.log flask/bin/uwsgi -s 127.0.0.1:9002 –need-app –wsgi-file app.py –processes 1 –callable app –daemonize /opt/logs/KVAutobus-uwsgi_02.log flask/bin/uwsgi -s 127.0.0.1:9003 –need-app –wsgi-file app.py –processes 1 –callable app –daemonize /opt/logs/KVAutobus-uwsgi_03.log flask/bin/uwsgi -s 127.0.0.1:9004 –need-app –wsgi-file […]

使用nginx和Python更新期间防止网站停机

我有一个在Ubuntu上托pipe的活动网站,使用nginx,网站是用Python编写的(CherryPy是服务器,Bottle是框架)。 我有一个shell脚本,复制python文件,通过现有的活网站,然后结果CherryPy重新启动服务器,以便它运行最新的代码(我想要它)。 问题是,在停止和开始的时间之间,默认的静态页面显示给那些试图在当时查看网站页面的不幸的人(希望他们没有提交表单)。 我在更新的时候看过这个页面。 我目前的设置是在两个反向代理nginx的端口上运行的网站的两个副本。 所以我想如果我更新一个,等待几秒钟,然后更新另一个网站将100%的时间,但这似乎并不是这样的情况? 比方说,我有端口8095和8096反向代理,都显示相同的网站,但在硬盘上它的两个相同的副本。 我更新端口8095的python文件,导致该端口closures,而CherryPy重新启动它。 难道每个人都不应该打8096? 它似乎并没有像这样工作。 我的文件复制脚本有8秒的延迟,根据CherryPy的日志,第二次停止重启6秒后重启,但是我看到了服务器closures时显示的默认静态离线页面。 我很困惑。 根据日志,总是有一个端口。 这是我的nginx.conf的一部分: upstream app_servers { server 127.0.0.1:8095; server 127.0.0.1:8096; } server { server_name www.mydomain.com; listen 80; error_page 502 503 /offline/offline.html; location /offline { alias /usr/share/nginx/html/mysite/1/views/; } location / { proxy_pass http://app_servers; proxy_redirect off; 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 […]

用uWSGI在Nginx后面扭曲的Web

我有一个用Twisted编写的自定义Websockets库,可以和Flask一起使用。 为我的应用程序启动开发服务器的行如下所示: resource = WSGIResource(reactor, reactor.getThreadPool(), app) static_resource = File(app.static_folder) log.startLogging(sys.stdout) ws = Resource() ws.putChild('chat', chat_resource) root_resource = WSGIRootResource(resource, {'static': static_resource, 'ws': ws}) site = Site(root_resource) if __name__ == '__main__': reactor.listenTCP(8000, site, interface='0.0.0.0') reactor.run() 我想用uWSGI而不是proxy_pass来为我的应用程序服务于Nginx。 什么是最简单的方法来做到这一点,因为我不能直接提供应用程序的WSGIResource?

nginx使用python进行http身份validation

我正在从Apache2迁移到NGinX,我想通过python脚本进行身份validation。 Apache2的工作configuration是: WSGIScriptAlias /hg $SCRIPT_DIR/hgwebdir.wsgi WSGIPythonPath $SCRIPT_DIR <Location /hg> AuthType Basic AuthName "Mercurial" AuthBasicProvider wsgi WSGIAuthUserScript $SCRIPT_DIR/authentication.py Require valid-user </Location> 什么是Nginx的等效configuration?

python进程需要时间在nginx和uwsgi上运行的django项目中启动

我开始使用python的多处理模块进程。 这个过程由django项目发送的post请求调用。 当我使用开发服务器(python manage.py runserver)时,发布请求不需要任何时间来启动进程并立即结束。 我使用nginx和uwsgi部署了生产项目。 现在,当我发送相同的发布请求时,大约需要5-7分钟来完成该请求。 它只发生在我开始一个过程的那些post请求。 其他post请求正常工作。 什么可能是这个延迟的原因? 我该如何解决这个问题?

在ubuntu 16.04上用nginx,uwsgi python-flask取得“502不良网关”

我正在按照这个在Ubuntu 16-04上部署一个应用程序(简单的hello world) 。 数字海洋教程 一切正常,直到testinguWSGI服务 。 之后,我按照描述的步骤,当我终于到达底部,检查服务器IP地址,然后我得到: 502 Bad Gateway 好的。 我search并检查了我的错误日志,我得到这个: – 2017/01/16 05:29:27 [crit] 20714#20714: *2 connect() to unix:/home/sajjan/project/project.sock failed (2: No such file or directory) while connecting to upstream, client: xx.9.xxx.xxx, server: 138.xxx.xx.xxx, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/home/sajjan/project/project.sock:", host: "xx.xx.xx.xx" 所以在采取错误日志之后,我手动创build了文件project.sock。 再次转到服务器的IP地址,然后相同的错误“502错误的网关” 再次检查错误日志,发现这一点 2017/01/16 06:07:11 [crit] 20874#20874: *1 connect() to […]

使用fcgiwrap的nginx上的Python – 上游从上游读取响应头时过早closuresFastCGI stdout

我想获得一个你好世界的Python脚本运行在我的nginx Web服务器上。 当我尝试加载URI时,出现“502 Bad Gateway”错误: http : //sub.dom.com/py-bin/hello.py 这是我的nginx错误日志中的错误。 2013/04/27 13:54:14 [error] 14158#0: *1 upstream closed prematurely FastCGI stdout while reading response header from upstream, client: wxyz, server: sub.dom.com, request: "GET /py-bin/hello.py HTTP/1.1", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "sub.dom.com" py-bin的位置:/home/cluber/www/sub.dom.com/py-bin public_html的位置:/home/cluber/www/sub.dom.com/public_html hello.py的位置:/home/cluber/www/sub.dom.com/py-bin/hello.py(chmod 777) fastcgi_params的位置:/ etc / nginx / fastcgi_params nginxconfiguration的内容 server { server_name sub.dom.com; access_log /home/cluber/www/sub.dom.com/logs/access.log; error_log […]