我需要使用Nginx和uWSGI部署一个flask应用程序并通过测试用例。
这是我的代码。
deploy.conf
server {
listen 8000;
location /Hello {
include uwsgi_params;
uwsgi_pass localhost:8081;
}
}
API.py**
from flask import Flask, request, make_response
app = Flask(__name__)
app.secret_key = "Thisisyoursecret"
@app.route('/Hello')
def hello():
res=make_response("Welcome to your flask application")
return res
if __name__ == "__main__":
app.run(host='0.0.0.0')
uwsgi.ini
[uwsgi]
socket = 127.0.0.1:8081
module = wsgi:app
master = true
processes = 5
wsgi.py
from api import app
if __name__ == "__main__":
app.run()
测试用例如下:
def test_hello_from_nginx_server(self):
url = "http://localhost:8000/Hello"
response = requests.get(url)
assert response.status_code == 200
assert response.text == 'Welcome to your flask application'
**这里是错误:assert 502 == 200
为什么我的状态码是502?
1条答案
按热度按时间at0kjp5o1#
你能试试下面的
deploy.conf
是否有效吗?