首页 > 解决方案 > Nginx 阻止数据库操作 mongodb flask

问题描述

我有一个烧瓶脚本,用于通过 pymongo 使用 Mongodb。它在开放的 5000 端口上工作正常,但是当我想通过 nginx 访问它时,出现错误

对于这个项目,我使用 nginx>uwsgi sock>wsgi.py> app.py uwsgi>wsgi.py>app.py 在开放 5000 端口上不使用 nginx 工作

server {
    listen 80;
    server_name my_ip;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/viktor/my_project/project.sock;
    }
}

Oct 11 12:05:08 funloot3 uwsgi[11123]: Traceback (most recent call last):
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app
Oct 11 12:05:08 funloot3 uwsgi[11123]:     response = self.full_dispatch_request()
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/flask/app.py", line 1951, in full_dispatch_request
Oct 11 12:05:08 funloot3 uwsgi[11123]:     rv = self.handle_user_exception(e)
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/flask/app.py", line 1820, in handle_user_exception
Oct 11 12:05:08 funloot3 uwsgi[11123]:     reraise(exc_type, exc_value, tb)
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
Oct 11 12:05:08 funloot3 uwsgi[11123]:     raise value
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/flask/app.py", line 1949, in full_dispatch_request
Oct 11 12:05:08 funloot3 uwsgi[11123]:     rv = self.dispatch_request()
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/flask/app.py", line 1935, in dispatch_request
Oct 11 12:05:08 funloot3 uwsgi[11123]:     return self.view_functions[rule.endpoint](**req.view_args)
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "./app.py", line 230, in my_stat
Oct 11 12:05:08 funloot3 uwsgi[11123]:     result = push_step(uid, request.args.get('steps'), request.args.get('timestamp'), request.args.get('check'))
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "./app.py", line 169, in push_step
Oct 11 12:05:08 funloot3 uwsgi[11123]:     step_user = steps_db.find_one({'uid': uid})
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/pymongo/collection.py", line 1273, in find_one
Oct 11 12:05:08 funloot3 uwsgi[11123]:     for result in cursor.limit(-1):
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/pymongo/cursor.py", line 1156, in next
Oct 11 12:05:08 funloot3 uwsgi[11123]:     if len(self.__data) or self._refresh():
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/pymongo/cursor.py", line 1050, in _refresh
Oct 11 12:05:08 funloot3 uwsgi[11123]:     self.__session = self.__collection.database.client._ensure_session()
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1807, in _ensure_session
Oct 11 12:05:08 funloot3 uwsgi[11123]:     return self.__start_session(True, causal_consistency=False)
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1760, in __start_session
Oct 11 12:05:08 funloot3 uwsgi[11123]:     server_session = self._get_server_session()
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1793, in _get_server_session
Oct 11 12:05:08 funloot3 uwsgi[11123]:     return self._topology.get_server_session()
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/pymongo/topology.py", line 482, in get_server_session
Oct 11 12:05:08 funloot3 uwsgi[11123]:     None)
Oct 11 12:05:08 funloot3 uwsgi[11123]:   File "/home/funloot/funloot/flaskenv/lib/python3.6/site-packages/pymongo/topology.py", line 205, in _select_servers_loop
Oct 11 12:05:08 funloot3 uwsgi[11123]:     self._error_message(selector))
Oct 11 12:05:08 funloot3 uwsgi[11123]: pymongo.errors.ServerSelectionTimeoutError: No replica set members found yet

屏幕截图中的追溯

在 imgur.com 上查看帖子

标签: pythonmongodbnginxflaskpymongo

解决方案


推荐阅读