我试图在dotcloud上部署nginx(v 1.3.14)后面的gunicorn + gevent。我有几个关于它的问题。我旨在修改python-on-dotcloud示例。到目前为止,我一直无法使用此设置获得websockets部分。换句话说,我必须手动刷新页面以获取更新,而不是通过socket.io。这对我来说都很新,所以这可能是一个总的noob错误。这是一个related question。gunicorn,nginx(v 1.3.14),django和gevent-socket.io,在dotcloud上
以下是我对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绑定到一个Unix套接字,然后设置从nginx.conf proxy_pass上游流量发送到与
proxy_pass http://appserver;
gunicorn我已经定义了应用服务器。我正在运行一个gevent-socket.io的django应用程序,它运行正常,没有运行nginx。 (我只是绑定gunicorn到0.0.0.0:$PORT_WWW在dotcloud.yml)
我的问题是这些。
我试图解决一个非问题?
a。我已经做了相当数量的阅读,建议将gunicorn放在nginx后面。在前线的dotcloud负载均衡器的情况下,这仍然是真的吗?
b。如果我不指望我会受到DoS攻击,那么将gunicorn放在nginx后面仍然很重要吗?
是否有可能通过unix套接字运行websockets,因为我试图设置?
unix套接字是否会在dotcloud上打破缩放?
如果我需要使用端口,请如何设置?我不认为我可以在同一个应用程序中分配两个http端口。如果我将它分成两个应用程序,那么我不知道如何将来自gunicorn应用程序的PORT_WWW环境变量传递给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 @[email protected] 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()
为了使事情更容易,我会从混合中删除nginx,除非你真的需要它。 Nginx并非真正需要,因为dotCloud网关将达到同样的目的。为了让事情变得更容易,你可以用本地python-worker做同样的事情,你根本不需要使用自定义服务。您只需运行gunicorn进程,并确保您以与自定义服务相同的方式请求http端口。 – 2013-03-08 18:38:42
这就是我期待的答案!谢谢,肯。 -Tim – t1m0 2013-03-08 20:10:23
更不用说websockets在nginx 1.4版本以下的任何东西都不完全支持,所以这可能是你的问题。除此之外,你的配置看起来不错。 – 2013-10-04 17:44:52