我有一个烧瓶应用程序,由uwsgi托管,nginx作为uwsgi的反向代理,使用内置的uwsgi代理模块.每当我访问重定向到另一个页面的页面时,Location标头指向非HTTPS URL.例如:
$ socat openssl:my-web-server:443 stdio
GET / HTTP/1.0
Host: my-web-server
HTTP/1.1 302 FOUND
Server: nginx/1.0.4
[...]
Location: http://my-web-server/login
Run Code Online (Sandbox Code Playgroud)
我的nginx配置看起来像这样:
server {
listen 80;
listen 443 ssl;
server_name my-web-server;
charset utf-8;
ssl_certificate /etc/nginx/certs/server.pem;
ssl_certificate_key /etc/nginx/certs/server.key;
location / {
uwsgi_pass unix:/tmp/uwsgi.sock;
include uwsgi_params;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用uwsgi作为我的Django(版本= 1.4)项目,但是如果我运行则会出错
uwsgi --ini django.ini
Run Code Online (Sandbox Code Playgroud)
from django.core.wsgi import get_wsgi_application ImportError: No module named django.core.wsgi
但我可以导入django.core.wsgi如下:
>>> import django.core.wsgi
Run Code Online (Sandbox Code Playgroud)
django.ini文件:
[uwsgi] chdir=/path/to/my/app module=app.wsgi:application master=True vacuum=True max-requests=5000 socket=127.0.0.1:9000
wsgi.py
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Run Code Online (Sandbox Code Playgroud) TL; DR编辑:我没有设置正确的文件夹权限.
当我运行烧瓶时,一切正常source venv/bin/activate && python run.py
.
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, world!"
if __name__ == "__main__":
app.debug = True
app.run(host='0.0.0.0', port=8080)
Run Code Online (Sandbox Code Playgroud)
但是当我使用nginx/emperor.uwsgi运行相同的应用程序时,每次命中服务器都会返回500.如果我注释掉SQLAlchemy导入,那么页面会按预期加载.
根据这个线程我尝试启用lazy/lazy-app,但它没有任何效果.Flask正在引发异常,因此nginx/uwsgi没有记录任何内容.
我尝试过使用from werkzeug.debug import DebuggedApplication
但仍然只是在我的浏览器中获得绝对的"内部服务器错误".
配置:
[uwsgi]
uid = http
gid = http
socket = /var/run/project.uwsgi.sock
chown-socket = http
chmod-socket = 664
pidfile = /var/run/project.master.pid
master = true
lazy = true
lazy-apps = true
chdir = /srv/http/project
python-path = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用uwsgi运行Django应用程序.我发现的大多数指令都引用了"--wsgi-file"和"--module"来指定应用程序,但是"uwsgi"没有提到这些选项,当我尝试使用它们时:
uwsgi -s /tmp/uwsgi.sock --master --module myapp.wsgi
uwsgi: unrecognized option '--module'
getopt_long() error
Run Code Online (Sandbox Code Playgroud)
和
uwsgi -s /tmp/uwsgi.sock --master --wsgi-file myapp/wsgi.py
uwsgi: unrecognized option '--wsgi-file'
getopt_long() error
Run Code Online (Sandbox Code Playgroud)
当我没有任何一个运行时,我得到:
uwsgi -s /tmp/uwsgi.sock --master
*** Starting uWSGI 2.0.9 (64bit) on [Fri Jul 10 11:12:04 2015] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-11) on 23 April 2015 19:31:15
os: Linux-2.6.32-504.16.2.el6.x86_64 #1 SMP Tue Mar 10 17:01:00 EDT 2015
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2 …
Run Code Online (Sandbox Code Playgroud) 我的应用程序使用nginx,在服务器端使用uWSGI.当我执行大量请求(响应时间> 4秒)时,会出现以下内容:
SIGPIPE: writing to a closed pipe/socket/fd (probably the client
disconnected) on request _URL_ (ip XX.XX.XX.XX) !!!
uwsgi_response_writev_headers_and_body_do(): Broken pipe
[core/writer.c line 287] during GET _URL_ (XX.XX.XX.XX)
OSError: write error
Run Code Online (Sandbox Code Playgroud)
似乎uWSGI尝试在流中写入,但此流已经关闭.当我检查nginx log(error.log)时:
upstream prematurely closed connection while reading response
header from upstream ...
Run Code Online (Sandbox Code Playgroud)
当然,我的客户端(REST客户端或浏览器)收到502错误.
我总是在~4s后得到这个错误.
但是,我不知道如何防止这个问题.我试着在我的nginx配置文件中设置一些参数:
location my_api_url {
[...]
uwsgi_buffer_size 32k;
uwsgi_buffers 8 32k;
uwsgi_busy_buffers_size 32k;
uwsgi_read_timeout 300;
uwsgi_send_timeout 300;
uwsgi_connect_timeout 60;
}
Run Code Online (Sandbox Code Playgroud)
但问题仍然存在.我还尝试在uWSGI配置文件(wsgi.ini)中设置这些参数:
buffer-size=8192
ignore-sigpipe=true
ignore-write-errors=true
Run Code Online (Sandbox Code Playgroud)
在尝试优化响应时间之前,我希望这个问题有一个解决方案.我没有找到一个在另一篇文章中工作的人.我使用大量数据,因此在某些情况下,我的响应时间将在4到10秒之间.
希望你能帮我 :)
非常感谢提前.
我有一台服务器,需要几分钟时间来处理特定请求然后响应它.
客户端必须等待响应,而不知道何时完成.
有没有办法让客户知道处理状态?(比如50%完成,80%完成),客户不需要轮询状态.
我对系统管理员和开发人员有疑问.我看到uWSGI允许我在运行uWSGI时设置数字或工作人员或进程,我已经读过它取决于已安装的机器,所以我有下一个问题:
worker_processes
nginx.conf 中的配置是否会影响这个?concurrency
与此相关?我已经在这个问题上敲打了好几天,终于到了一堵砖墙.
我一直试图让我的堆栈运行:
我一直在看其他一些SO这样的文章:
nginx - uWSGI HTTP + websocket配置
他们似乎遇到了类似的问题,但解决方案对我不起作用.
基本上,每当我尝试启动我的uWSGI进程时,我都会遇到nginx 502坏网关屏幕.根据文档中的说明,我有两个单独的uwsgi进程在运行.
当我运行websocket uwsgi实例时,我得到以下内容:
*** running gevent loop engine [addr:0x487690] ***
[2015-05-27 00:45:34,119 wsgi_server] DEBUG: Subscribed to channels: subscribe-broadcast, publish-broadcast
Run Code Online (Sandbox Code Playgroud)
这告诉我,uwsgi实例运行正常.然后我运行我的下一个uwsgi进程,没有错误记录那里...
当我导航到浏览器中的页面时,该页面会挂起几秒钟,然后才能获得502 Bad Gateway屏幕.
根据NGINX日志,NGINX说:
2015/05/26 22:46:08 [error] 18044#0: *3855 upstream prematurely closed connection while reading response header from upstream, client: 192.168.59.3, server: , request: "GET /chat/ HTTP/1.1", upstream: "uwsgi://unix:/opt/django/django.sock:", host: "192.168.59.103:32768"
Run Code Online (Sandbox Code Playgroud)
这是我尝试在Web浏览器中访问该页面时获得的唯一错误日志.
任何人的想法???
以下是我的一些配置文件:
nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http { …
Run Code Online (Sandbox Code Playgroud) 我有一个Django应用程序Web应用程序,我想知道是否有可能让nginx传播中止/接近uwsgi/Django.
基本上我知道nginx的是意识到过早中止/接近,因为它默认为uwsgi_ignore_client_abort
"关",你会得到499个nginx的错误,在你的nginx的日志时,请求中止/关闭发送响应之前.一旦uwsgi完成处理请求,它将返回响应nginx时抛出"IO错误".
转向uwsgi_ignore_client_abort
"on"只是让nginx不知道中止/关闭,并删除了uwsgi"IO错误",因为uwsgi仍然可以回写给nginx.
我的用例是我有一个应用程序,人们可以非常快速地通过一些ajax结果页面,因此如果快速页面通过我中止了他们跳过的页面的待处理ajax请求,这将使客户端保持清洁和高效.但这对服务器端(uwsgi/Django)没有任何作用,因为即使没有任何东西等待响应,它们仍然必须处理每个请求.
现在显然可能存在某些页面,我不希望请求因任何原因而过早中止.但我使用芹菜来处理可能属于该类别的长期运行请求.
这可能吗?uwsgi's
hariakari设置让我觉得它在某种程度上......只是无法弄清楚如何去做.
我试图用金字塔设置uWSGI,但是在尝试时我收到了这个错误 uwsgi --ini-paste development.ini
Python version: 3.2.3
错误信息:
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
Python version: 3.2.3 (default, Oct 19 2012, 20:08:46) [GCC 4.6.3]
Set PythonHome to /root/path/to/virtualenv
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named encodings
Run Code Online (Sandbox Code Playgroud)
这是我在development.ini中的内容
[uwsgi]
socket = /tmp/uwsgi.sock
master = true
processes = 4
harakiri = 60
harakiri-verbose = true
limit-post = 65536
post-buffering = 8192
daemonize = ./uwsgi.log
pidfile = ./pid_5000.pid
listen = 256
max-requests …
Run Code Online (Sandbox Code Playgroud)