Python 502使用flask restplus时nginx服务器上出现错误网关
仅当我将flask restplus与nginx服务器一起使用时,才会发生此错误。仅使用flask时,服务器工作正常;本地运行应用程序时,flask restplus api工作正常,甚至可以使用:Python 502使用flask restplus时nginx服务器上出现错误网关,python,nginx,flask,uwsgi,flask-restplus,Python,Nginx,Flask,Uwsgi,Flask Restplus,仅当我将flask restplus与nginx服务器一起使用时,才会发生此错误。仅使用flask时,服务器工作正常;本地运行应用程序时,flask restplus api工作正常,甚至可以使用: uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:application 在我的EC2实例上 我曾尝试在nginx一侧使用gunicorn(而不是uwsgi),但在我的/var/log/nginx/error.log文件中出现了相同的错误: 2
uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:application
在我的EC2实例上
我曾尝试在nginx一侧使用gunicorn(而不是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)
我的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\u test\u app.service文件如下:
server {
listen 80;
server_name #.#.#.#;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/jamie/my_app/my_app.sock;
}
}
[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
如果有人知道是什么导致了这个问题,我将非常感谢你的回答,因为我已经有一段时间无法解决这个问题了 您是否尝试过切换调试选项?它可能会向您显示更多的信息。如果name==“main”:application.run(host=“0.0.0.0”,debug=True),您可以发布nginx虚拟主机配置吗?如果您已经学习了digitalocean教程,最有可能的是/etc/nginx/sites available/.Sure@JavierLopez文件夹中的文件。我将使用“find/home/jamie/my_app/name my_app.sock”将其添加到my_app.sock文件的原始postLook中,以检查它是否是您在虚拟主机中设置的位置。您是否尝试切换调试选项?它可能会向您显示更多的信息。如果name==“main”:application.run(host=“0.0.0.0”,debug=True),您可以发布nginx虚拟主机配置吗?如果您已经学习了digitalocean教程,最有可能的是/etc/nginx/sites available/.Sure@JavierLopez文件夹中的文件。我将使用“find/home/jamie/my_app/name my_app.sock”将其添加到my_app.sock文件的原始postLook中,以检查它是否是您在虚拟主机中设置的位置。