- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我很难使用 Flask-Restplus 部署 Flask 应用程序。
在 http://localhost:5000/api 本地工作 (wezkrug) 时一切正常
但是当我使用 nginx + uwgsi 在计算机中部署我的应用程序时,在访问 http://example.com/api 时,我不断收到来自服务器的 404 响应...
看起来 Flask-Restplus 正在为 Swagger 使用 swaggerui...我是否必须在 nginx.conf 中添加一些内容来提供此服务?原谅我的无知,但我以前没有使用过 nginx 的经验
这就是我声明包含 API 的蓝图的方式
# Configure the Blueprint for API
blueprint = Blueprint('api', __name__, url_prefix='/api')
api.init_app(blueprint)
api.add_namespace(programs_namespace)
api.add_namespace(students_namespace)
app.register_blueprint(blueprint)
这是我的 nginx 配置,位于/etc/ngingx/conf.d/mysite.conf
server {
listen 80;
server_name _;
client_max_body_size 400M;
location / {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
try_files $uri @app;
}
location /static/ {
root /home/mysite/mysite/portal/src/portal;
access_log off;
error_page 404 = @app;
expires 7d;
}
location @app {
include uwsgi_params;
uwsgi_pass 127.0.0.1:5000;
access_log /var/log/nginx/mysite_access.log main;
error_log /var/log/nginx/mysite_error.log warn;
}
}
# SSL Server
server {
listen 443 default_server ssl;
client_max_body_size 400M;
ssl_certificate /etc/nginx/conf.d/mysite.crt;
ssl_certificate_key /etc/nginx/conf.d/mysite.key;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
keepalive_timeout 70;
location / {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
try_files $uri @app;
}
location /static/ {
root /home/mysite/mysite/portal/src/portal;
access_log off;
error_page 404 = @app;
expires 7d;
}
location @app {
include uwsgi_params;
uwsgi_pass 127.0.0.1:5000;
access_log /var/log/nginx/mysite_access.log main;
error_log /var/log/nginx/mysite_error.log warn;
}
}
我必须说,当我尝试访问http://example.com/api时我在日志文件中根本没有得到任何输出。
该应用程序是通过使用 uwgsi 的 init 脚本运行的,您可以在此处查看内容:
mysite_dir=${mysite_DIR-/home/mysite/mysite/portal/src/portal}
pidfile=${PIDFILE-/var/run/mysite/mysite.pid}
uwsgi_bin=/usr/local/bin/uwsgi
uwsgi_url=127.0.0.1:5000
uwsgi_app=uwsgiapp
uwsgi_parameters="-p 4 -M -t 300"
logfile=${LOGFILE-/var/log/mysite.log}
user=mysite
chk_pidfolder() {
[ -d "${pidfile%/*}" ] || install -o $user -g $user -d "${pidfile%/*}"
}
start() {
log_daemon_msg "Starting mysite"
start-stop-daemon --start -c $user -g $user --pidfile $pidfile --exec $uwsgi_bin -- --chdir $mysite_dir --pidfile $pidfile -s $uwsgi_url -w $uwsgi_app $uwsgi_parameters -d $logfile --callable app --enable-threads --post-buffering 4096
log_end_msg $?
}
stop () {
log_daemon_msg "Stopping mysite"
if [ -e "$pidfile" ]; then
pid=`cat "$pidfile"`
else
pid=`pidofproc $uwsgi_bin`
fi
kill $pid
stopped=false
for ((i=0; i<10; i++)); do
if [ -d /proc/$pid ]; then
printf "."
sleep 2
else
stopped=true
break
fi
done
if $stopped ; then
rm -f $pidfile
log_end_msg 0
else
kill -6 $pid
log_warning_msg "no success, attempted to kill the process with -6, manual check recommended"
fi
}
case "$1" in
start)
chk_pidfolder
start
;;
stop)
stop
;;
status)
log_daemon_msg "Status of mysite"
status_of_proc -p $pidfile $uwsgi_bin mysite
# if [ $? -eq 0 ]; then
# log_end_msg 0
# exit 0
# else
# log_end_msg 1
# exit 1
# fi
;;
restart)
log_daemon_msg "Restarting mysite"
stop
sleep 4
start
;;
*)
echo $"Usage: $prog {start|stop|restart}"
exit 2
;;
esac
exit 0
谢谢!
最佳答案
如 Flask's documentation 中所述,您可能想要使用 ProxyFix + 对 nginx 配置进行一些修改。
在您的应用程序代码中,您可能想要执行以下操作:
# Configure the Blueprint for API
blueprint = Blueprint('api', __name__, url_prefix='/api')
api.init_app(blueprint)
api.add_namespace(programs_namespace)
api.add_namespace(students_namespace)
app.register_blueprint(blueprint)
# Here we patch the application
from werkzeug.contrib.fixers import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app)
那么你的 nginx 配置必须如下:
server {
listen 80;
server_name _;
client_max_body_size 400M;
location / {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
try_files $uri @app;
}
location /static/ {
root /home/mysite/mysite/portal/src/portal;
access_log off;
error_page 404 = @app;
expires 7d;
}
location @app {
include uwsgi_params;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
uwsgi_pass 127.0.0.1:5000;
access_log /var/log/nginx/mysite_access.log main;
error_log /var/log/nginx/mysite_error.log warn;
}
}
# SSL Server
server {
listen 443 default_server ssl;
client_max_body_size 400M;
ssl_certificate /etc/nginx/conf.d/mysite.crt;
ssl_certificate_key /etc/nginx/conf.d/mysite.key;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
keepalive_timeout 70;
location / {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
try_files $uri @app;
}
location /static/ {
root /home/mysite/mysite/portal/src/portal;
access_log off;
error_page 404 = @app;
expires 7d;
}
location @app {
include uwsgi_params;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
uwsgi_pass 127.0.0.1:5000;
access_log /var/log/nginx/mysite_access.log main;
error_log /var/log/nginx/mysite_error.log warn;
}
}
关于python - 如何使用 nginx + uwsgi 部署 Flask-restplus 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40684249/
我正在遵循Flask-potion教程并尝试保护我的api。我一直试图找出如何在User端点上设置权限,以使一个User无法查看另一个User的记录。这是我的代码: class UserResourc
项目设置 Python 3.5.3 flask 0.12.2 目录 . ├── Core │ ├── BackgroundProcessManager.py │ ├── FirebaseDat
我正在构建 flask 应用程序并决定这次尝试应用程序工厂方法,但是遇到了 flask 迁移的麻烦并且无法找出简单的解决方案。 请注意,我想将配置位置作为选项传递给脚本 管理.py: manager
我尝试通过以下示例代码来熟悉Flask-APScheduler插件:https://github.com/viniciuschiele/flask-apscheduler/blob/master/ex
我一周前刚刚了解了 Flask 和 JWT,所以我真的需要一些帮助。有人可以解释一下flask-jwt和flask-jwt-extended之间的区别吗? 最佳答案 Flask-JWT 没有那么多功能
我是 Flask 的新手,我只是想用它创建一个简单的市场。我的网站上有三种类型的用户 [卖家、买家、管理员]。我认为每种类型的用户都应该有自己的注册和登录,因为他们的角色应该提供不同类型的信息。另一方
基本上,我想做一些非常简单的事情:我想创建一个用于删除数据库中条目的表单。 模板正在创建一个包含所有条目的html表,没有任何麻烦。我现在的问题是:如何将其转换为每行都有链接的表单。 当然,我可以通过
我对Flask来说非常陌生,其中一个基本要求是我需要SEO友好的URL。 我说一条路线 @app.route('/sales/') @app.route(/sales/) def get_sales(
一直在为用户管理系统开发Flask-user,但是我看不到自定义登录页面和注册页面的方法。我使用pip安装了flask-user pip install flask-user 任何帮助,将不胜感激 最
我有一个奇怪的情况,不知道如何找到问题。 我已经创建了一个这样的蓝图 reportjobsmod = Blueprint('jobreports', __name__, url_prefix='/jo
我认为在 Flask 中拥有实例变量的正确方法是添加用户和 session ,但我正在尝试测试一个概念,我还不想经历所有这些。我试图让一个网络应用程序将图像加载到一个变量中,然后可以对其执行不同的图像
select = SelectField("City") form.select.choices = [(places['name'], places['name']) for places in p
这个问题在这里已经有了答案: Provide extra information to Flask's app.logger (2 个回答) 3年前关闭。 我正在运行一个 flask 应用程序。我想写
我当时正在编程一个非常不错的api,使用json从游戏服务器到我的网站空间获取一些json数据, 但是每次我使用angular发送请求时,我都会得到以下信息:127.0.0.1--[20 / Mar
我已经开发了一个上传表单,以将特定的.xlsx文件作为上传。要求是要处理非xlsx上载的任何异常(例如zip,exe文件)。我正在使用pyexcel库读取上传内容。我尝试创建以下代码来处理此异常: e
我使用此功能在网站上捕获404错误: @app.errorhandler(404) def page_not_found(e): logger.warning('User raised an
我正在尝试同时使用 Flask Restful 和 Flask SocketIO。我已经制作了一个 Flask Restful 应用程序,但现在我想使用 Flask SocketIO 在客户端和我的服
我有一些 Flask 应用程序,我通过设置 FLASK_APP 来运行它们。环境变量和调用 flask run .自 FLASK_DEBUG也设置了,每当我更改一些代码时,应用程序都可以方便地重新加载
我目前正在使用 Flask 构建一个应用程序。我正在努力访问 Flask 实例“app”以及 Flask-mail 实例“mail”。 下面是我的项目的样子: └── my-project ├
Remember-me是 parameter flask_login.login_user(user, remember=False, duration=None, force=False, fres
我是一名优秀的程序员,十分优秀!