1.配置好了Flask + virtualenv +uWSGI,启动uWSGI并调试,网页显示 Internal Server Error
参考:https://www.cnblogs.com/cleven/p/10911099.html
【uwsgi.ini】
[uwsgi] http=0.0.0.0:8080 pythonpath = /home/ubuntu/myprojects/myflask wsgi-file=mytest.py #问题出在这里:这里需要绝对路径。。。 callable=app processes=4 threads=2 master=True logto=log.txt
【解决方案】
wsgi-file = /home/ubuntu/myprojects/myflask/mytest.py
2.已经配置好了文件:flask.conf,网页打开仍然是Nginx的欢迎页面,为什么?
配置文件构成:
/etc/nginx/nginx.conf
└ /etc/nginx/conf.d/flask.conf
└ /etc/nginx/sites-enable/default
##### # nginx.conf ##### user www-data; worker_processes auto; pid /run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; #问题出在这里 } ##### # flask.conf ##### server { listen 80; server_name 49.234.18.49; root /home/ubuntu/myprojects/myflask; location / { include uwsgi_params; uwsgi_pass localhost:8080; } } ##### # default ##### server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name _; location / { try_files $uri $uri/ =404; } }
【原因】
nginx.conf中include了两个地址,其中 /etc/nginx/sites-enabled/* 占用了80端口,导致flask.conf设置的端口失效。
解决方法就是注释掉这一行:# /etc/nginx/sites-enabled/* ;
3.启动flask的时候出现ImportError: No module named flask
【原因】
新建虚拟环境的时候出错导致的,排查了一晚上,谨记谨记!
注:神tm虚拟环境中sudo pip install 的时候是安装到实际环境中去的!!!
4.网页部署完成,初次访问速度奇慢无比,如何解决?
[思路]
vue router 懒加载
5.客户端登录的时候返回500 (INTERNAL SERVER ERROR),如何解决?
查看uwsgi的Log如下:
File "/home/ubuntu/release/myblog_flask_v2/app/models.py", line 104, in get_jwt return jwt.encode( AttributeError: module 'jwt' has no attribute 'encode'
【原因】
包装错了啊
错误包:jwt
正确包:pyjwt
emmmm....