- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 dotcloud 上的 nginx(v 1.3.14)后面部署 Gunicorn + gevent。我对此有几个疑问。我的目标是适应 python-on-dotcloud例子。到目前为止,我还无法让 websockets 部分与此设置一起使用。换句话说,我必须手动刷新页面才能获取更新,而不是通过 socket.io。这对我来说都是新鲜事,所以这可能完全是菜鸟错误。这是related question .
以下是我对 python-on-dotcloud 示例所做的更改。
显然 nginx (since version 1.3.13) supports web sockets 。我从 python-on-dotcloud 示例更新了构建器脚本以指向此开发版本:nginx_download_url="http://nginx.org/download/nginx-1.3.14.tar.gz"
我将gunicorn设置为绑定(bind)到unix套接字,然后从nginx.conf设置proxy_pass,以使用proxy_pass http://appserver;
将流量上游发送到gunicorn,其中我有定义的应用程序服务器。
我正在使用 gevent-socket.io 运行一个 django 应用程序,无需运行 nginx 即可正常工作。 (我只是将gunicorn绑定(bind)到dotcloud.yml中的0.0.0.0:$PORT_WWW)
我的问题是这些。
我是否在尝试解决一个非问题?
a.我已经阅读了大量建议将 Gunicorn 放在 nginx 后面的文章。在前线的 dotcloud 负载均衡器的背景下,这仍然是真的吗?
b.如果我预计不会受到 DoS 攻击,那么将 Gunicorn 放在 nginx 后面还重要吗?
是否可以像我尝试设置的那样通过 unix 套接字运行 websockets?
unix 套接字会破坏 dotcloud 上的缩放吗?
如果我需要使用端口,该如何设置?我不认为我可以在同一个应用程序中分配两个 http 端口。如果我将其分成两个应用程序,那么我不确定如何将 PORT_WWW 环境变量从 Gunicorn 应用程序传递到 nginx 应用程序,以便它最终可用于 nginx 安装后脚本,从而在生成的 nginx.conf 中可用。
对于为什么这不能按原样工作有什么想法吗?
我在下面包含了三个配置文件。让我知道其他人是否会提供帮助。谢谢!
dotcloud.yml
www:
type: custom
buildscript: python/builder
systempackages:
# needed for the Nginx rewrite module
- libpcre3-dev
# needed to support python versions 2.7, 3.1, 3.2.
- python3-all
ports:
www: http
processes:
nginx: nginx
app: /home/dotcloud/env/bin/gunicorn -c /home/dotcloud/gunicorn.conf -b unix:/tmp/gunicorn.sock wsgi:application
#app: /home/dotcloud/env/bin/gunicorn -c /home/dotcloud/gunicorn.conf -b 0.0.0.0:$PORT_WWW wsgi:application
config:
# python_version can have one of the following values (2.6, 2.7, 3.1, 3.2). 2.6 is the default if no value is entered.
python_version: 2.7
data:
type: redis
db:
type: postgresql
nginx.conf.in(与常规 nginx.conf 相同,只是 PORT_WWW 等待交换为真实端口号)
# template for nginx.conf file.
# the file will be processed by the postinstall script
# it will insert the correct value for PORT_WWW and then put this
# file in /home/dotcloud/nginx/conf/nginx.conf when done.
# nginx will be managed by supervisord when it starts so we don't need daemon mode
daemon off;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
log_format combined-realip '$remote_addr ($http_x_real_ip) - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
access_log /var/log/supervisor/nginx_access.log combined-realip;
error_log /var/log/supervisor/nginx_error.log error;
gzip on;
upstream appserver {
server unix:/tmp/gunicorn.sock;
# For a TCP configuration:
# server 192.168.0.7:8000 fail_timeout=0;
}
server {
# PORT_WWW value is added via postinstall script.
listen @PORT_WWW@ default;
server_name localhost;
root /home/dotcloud/current/;
location / {
if ( -f /home/dotcloud/current/maintenance) {
return 503;
}
proxy_pass http://appserver;
proxy_http_version 1.1;
proxy_set_header upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
error_page 404 @404;
error_page 500 @500;
error_page 502 @502;
error_page 503 @503;
error_page 504 @504;
location @404 {
rewrite ^ /static/404.html;
}
location @500 {
rewrite ^ /static/500.html;
}
location @502 {
rewrite ^ /static/502.html;
}
location @503 {
rewrite ^ /static/503.html;
}
location @504 {
rewrite ^ /static/504.html;
}
location /static {
alias /home/dotcloud/current/static;
}
location /robots.txt {
alias /home/dotcloud/current/static/robots.txt;
}
location /favicon.ico {
alias /home/dotcloud/current/static/favicon.ico;
}
}
}
gunicorn.conf
workers = 1
worker_class = 'socketio.sgunicorn.GeventSocketIOWorker'
pidfile = '/tmp/gunicorn.pid'
debug = True
loglevel = 'debug'
errorlog = '/var/log/supervisor/gunicorn.log'
django_settings='/home/dotcloud/settings.py'
def post_fork(server, worker):
from psycogreen.gevent import patch_psycopg
patch_psycopg()
# MySQL
#def post_fork(server, worker):
# import pymysql
# pymysql.install_as_MySQLdb()
最佳答案
我在上面提出了 5 个相关问题,我将尝试在这里回答前 3 个问题。 (我对 dotcloud 的基础了解不够,无法回答最后两个问题)。我还预计大多数人发现这个问题主要集中在带有gunicorn和nginx的websocket上(较少关注dotcloud细节)。对于这些人,您可以跳转到此处的引用设置:gunicorn deployment scheme with nginx
Am I trying to solve a non-problem?
a. I've done a fair amount of reading where it's advised to put gunicorn behind nginx. In the context of dotcloud's load balancers on the front line, is this still true?
b. If I don't expect that I'll be subject to a DoS attack, is it still important to put gunicorn behind nginx?
根据 Ken Cochrane 上面的评论,我相信 dotcloud 基础设施本身提供了 nginx 通常在 DIY 设置中提供的安全性。因此,在这种特殊情况下,这确实是“没问题的”。然而,一般来说,您确实希望在 nginx 后面使用 Gunicorn,并且您绝对可以使用该设置运行 websockets。
- Is it possible to run websockets through a unix socket as I have attempted to setup?
是的。这是 gunicorn deployment scheme with nginx 的一个很好的引用。 。对于 Websocket,请务必阅读整个部分并包含 proxy_buffering off;
- Will the unix sockets break scaling on dotcloud?
我的理解是套接字和端口应该同样工作。
关于django - Gunicorn、nginx(v 1.3.14)、django 和 gevent-socket.io,位于 dotcloud,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15297184/
我尝试了几乎所有命令来杀死 gunicorn 服务器。但没有任何效果。我怎样才能杀死这些进程并释放 80 端口 12652 ? Ss 0:00 sudo gunicorn -b
我正在使用 Apache Airflow,发现 gunicorn-error.log 的大小在 5 个月内增长了超过 50 GB。大多数日志消息都是 INFO 级别的日志,例如: [2018-05-1
我正在使用 在 Digital Ocean 上运行 django gunicorn 和 nginx . Gunicorn 用于为静态文件提供 django 和 nginx。 通过网站上传文件后,我无法
我正在使用 Django 1.8,我想用 gunicorn 运行我的应用程序。 我可以从命令行绑定(bind)到我的 IP 运行它: gunicorn myapp.wsgi:application -
我们正在使用 https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker FastAPI 并且能够使用 gunicorn 日志文件自定义我们
我在 docker 上的 centos7 上运行 Airflow 1.8,但我的网络服务器无法访问浏览器。我通过pip2.7安装了airflow。 Flower ui 显示良好,initdb 运行连接
gunicorn.service cannot open WorkingDirectory and the gunicorn executable. I think it's about per
任何想法为什么我的 gunicorn 服务器无法启动? jeffy@originaldjangster:~$ sudo /home/jeffy/django_files/django_test_ven
我已经安装了gunicorn,但是没有找到gunicorn命令: # pip3.4 install gunicorn Requirement already satisfied (use --upgr
我在有监督的ginicorn部署我的django项目。 我在virtualenv中安装了gunicorn,添加到INSTALL_APPS中。 命令./manage.py run_gunicorn -b
我成功安装了gunicorn: remote: -----> Removing .DS_Store files remote: -----> Python app detected remote: -
Systemd 和 Gunicorn 需要某种 wsgi 文件作为 ExecStart 的最后一个参数:http://docs.gunicorn.org/en/latest/deploy.html?h
我正在尝试将基本应用程序部署到 Amazon EC2使用 Django , Gunicorn , 和 Nginx .我有应用 git clone进入我的AWS Ubuntu实例并正在运行 Django
在更新为使用小型模型中的 spacy_en_core_web_lg 后,我的 fastapi 服务器内存不足。 当运行 fastapi 时,会生成 4 个 gunicorn worker,并且根据内存
我有一个基于这个的 ansible 配置虚拟机 https://github.com/jcalazan/ansible-django-stack但出于某种原因,尝试启动 Gunicorn 会出现以下错
我关注 this如何在 Ubuntu 18.04 指南中使用 Postgres、Nginx 和 Gunicorn 设置 Django。 我创建了以下文件 .socket sudo nano /etc/
我正在尝试按照此 [链接][1] 在 Digital Ocean 上部署简单的 Django 应用程序用 gunicorn 实现它的抛出错误 gunicorn.service: Failed with
这里我想问你,用python运行gunicorn uvicorn,和默认从tiangolo有什么区别? 我尝试使用 JMeter 对这些进行压力测试具有线程属性: 从这些,我得到了结果:: 从上面我尝
因此,我有一个简单的 Flask API 应用程序,它运行在运行 tornado worker 的 gunicorn 上。 gunicorn 命令行是: gunicorn -w 64 --backlo
我已经使用 Gunicorn + Nginx + Supervisor 部署了一个 Django 1.6 应用程序。一切正常,但我的 Gunicorn error.log 一直在发送错误。该文件很大,
我是一名优秀的程序员,十分优秀!