【问题标题】:running uwsgi as master won't handle requests以 master 身份运行 uwsgi 不会处理请求
【发布时间】:2015-12-15 11:50:19
【问题描述】:

我有以下设置

src
|
|--flask_app
|--|--controllers.py
|--|--provider.py
|--|--__init__.py
|--config.py
|--wsgi.py
|--myproject.ini
|--myproject.sock

init.py 创建烧瓶应用程序

from flask import Flask, g
from flask_app.controllers import api_module
from flask_app.provider import CassandraDbProvider


# Define WSGI application object

app = Flask(__name__)

# Configure it

app.config.from_object('config')

cassandra = CassandraDbProvider(**app.config['DATABASE_CONNECT_OPTIONS'])



@app.before_request
def before_request():
    g.db = cassandra


app.register_blueprint(api_module)

controler.py 具有在端点上运行的视图并创建蓝图

最后wsgi.py有如下代码

from cassandra_flask_app import app as application

if __name__ == "__main__":
application.run(host="0.0.0.0", port=5000)

我的项目.ini

[uwsgi]
module = wsgi

logto = /var/log/uwsgi/uwsgi.log

threads = 10

socket = myproject.sock
chmod-socket = 664
vacum = true

die-on-term = true

新贵脚本

description "uWSGI server instance configured to serve myproject"

start on runlevel [2345]
stop on runlevel [!2345]

setuid myuser
setgid www-data

env PATH=/home/myuser/myproject/myprojectenv/bin
chdir /home/myuser/myproject/src
exec uwsgi --ini myproject.ini

和 nginx

server {
    listen 80;
    server_name myIpHere;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/myuser/myproject/src/myproject.sock;
    }
}

controller.py

api_module = Blueprint('my_api', __name__, prefix='/api') # this might be wrong now because I don't have code infront of me

#myvmip/api/ works fine when uwsgi is master
@api_module.route('/', methods=['GET']):
def test_url():
    return 'c'

#myvmip/api/normal_view/?query1=some_value" doesn't work when in master with no error. Only connection timeout error in nginx error.log.
@api_module.route('/nomral_view/', methods=['GET'])
def normal_view():
    get_parameter = request.args.get('query1')
    #uses g.db to connect to database and fetch some results
    #database is cassandra db
    return jsonify(**json) 

它在我的开发机器上运行良好。在我的虚拟机上,我使用 nginx 和 uwsgi 加载我的烧瓶应用程序。我已经按照互联网上许多教程中的描述设置了 uwsgi。问题是,如果我以主服务器身份运行 uwsgi,那么它将无法访问我的一些网址。禁用它可以正常工作。你认为它可能是什么? uwsgi 没有加载为主有关系吗?

【问题讨论】:

  • 你有任何 uWSGI 错误日志吗?
  • Uwsgi 有很多选择。请发布您正在使用的 ini 文件(或命令行参数)。
  • @iurisilvio 没有错误日志,只是超时。好像没有到达 uwsgi。
  • 这是一个很好的问题,但缺少一些关键信息。 some of my urls -> 哪个网址。我们需要查看这些网址的代码。我们需要 Nginx 日志。我们需要 UWSGI 日志。
  • 尝试直接从终端运行uWSGI,而不是从暴发户那里看你是否得到更多的输出。

标签: python nginx flask uwsgi


【解决方案1】:

您需要将以下内容添加到您的 myproject.ini 文件中

chdir = /path/to/project
callable = application

http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html#deploying-flask

另外,如果你有一个 virtualenv,你应该添加

venv=/path/to/venv

【讨论】:

  • 我在 Upstart 文件中设置了环境。我在这里使用了本教程goo.gl/wM3zP1
猜你喜欢
  • 2016-02-05
  • 1970-01-01
  • 1970-01-01
  • 2012-10-14
  • 2014-07-16
  • 1970-01-01
  • 2020-08-16
  • 1970-01-01
  • 2011-01-15
相关资源
最近更新 更多