使用flask restplus

时间:2017-07-03 21:50:49

标签: python nginx flask uwsgi flask-restplus

仅当使用带有nginx服务器的flask restplus时,才会出现此错误。使用flask时服务器正常工作,在本地运行应用程序时,flask-restplus api工作正常,甚至是:

uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:application

在我的EC2实例上。

我尝试过使用gunicorn和nginx(而不是uwsgi),但我在/var/log/nginx/error.log文件中遇到了同样的错误:

2017/07/03 20:30:02 [crit] 957#957: *1 connect() to unix:/home/jamie/my_app/my_app.sock failed 
(2: No such file or directory) while connecting to upstream,
client: #.#.#.#, server: #.#.#.#, request: "GET /favicon.ico HTTP/1.1", upstream: 
"uwsgi://unix:/home/jamie/my_app/my_app.sock:", host: "#.#.#.#", referrer: "http://#.#.#.#/"

该应用程序通过wsgi.py来实现,如下所示:

from main import application

if __name__ == "__main__":
    application.run('0.0.0.0')

main.py文件包含以下内容:

 from boto3 import resource
 from flask import json, request, abort
 from flask import Flask
 from flask_restplus import Api, Resource, fields

 application = Flask(__name__)
 api = Api(application)



@api.route('/users', methods=['GET', 'POST'])
class Users(Resource):
    def get(self):
        return users_get()

    @api.expect(resource_fields)
    def post(self):
         return user_login()


@api.route('/users/<string:Username>', methods=['GET', 'PUT', 'DELETE'])
class User(Resource):
    def get(self, Username):
         return user_get(Username)

    def put(self, Username):
        return create_user(Username)

    def delete(self, Username):
        return delete_user(Username)

为了配置我跟随this digitalocean tutorial的服务器,我的配置基本相同。如果有人想看到它,我可以提供它。

我的uwsgi ini文件如下:

[uwsgi]
module = wsgi:application

master = true
processes = 5
socket = my_app.sock
chmod-socket = 666
vacuum = true

die-on-term = true

我的nginx服务器配置位于etc / nginx / sites-available / my_app  像这样:

server {
    listen 80;
    server_name #.#.#.#;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/jamie/my_app/my_app.sock;
    }
}

最后我的/etc/systemd/system/fitness_test_app.service文件是这样的:

[Unit]
Description=uWSGI instance to serve my_app
After=network.target

[Service]
User=jamie
Group=www-data
WorkingDirectory=/home/jamie/my_app
Environment="PATH=/home/jamie/my_app/myprojectenv/bin"
ExecStart=/home/jamie/my_app/myprojectenv/bin/uwsgi --ini my_app.ini

[Install]
WantedBy=multi-user.target

如果有人知道什么可能导致这个问题,我将非常感谢答案,因为我已经有一段时间无法解决这个问题了。

0 个答案:

没有答案