在Nginx上部署Flask Rest API

时间:2017-08-25 09:52:02

标签: python rest nginx flask

有人可以帮我吗?我正在尝试在nginx上部署我的python flask rest api,但它不起作用。我跟着this tutorial但是老实说我不确定这是不是我需要做的事情(我已经完成了它仍然没有用)。

这是我api的代码:

from flask import Flask, jsonify, url_for, redirect, request
from flask_restful import Resource, Api, reqparse
from flask_cors import CORS, cross_origin

app = Flask(__name__)
CORS(app)
api = Api(app)

class CreateUser(Resource):
    def post(self):
        return jsonify({
            'status': 'ok', 
            'message': 'user successfuly created'
        })

api.add_resource(CreateUser, '/CreateUser')

if __name__ == '__main__':
    app.run(host='0.0.0.0')

VH配置:

server {
    listen 80;
    server_name api.domain.com;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/apirest/apirest.sock;
    }
}

我正在使用Postman Chrome应用程序,每次我向“api.domain.com/CreateUser”发出POST请求时都会收到404错误:

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

非常感谢!

0 个答案:

没有答案