cd /home
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2019.03-Linux-x86_64.sh
或者
wget https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh
bash Anaconda3-2019.03-Linux-x86_64.sh
修改了安装目录:/home/anaconda3
Anaconda3 will now be installed into this location:
/root/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/anaconda3] >>> /home/anaconda3
Thank you for installing Anaconda3!
===========================================================================
Anaconda and JetBrains are working together to bring you Anaconda-powered
environments tightly integrated in the PyCharm IDE.
PyCharm for Anaconda is available at:
https://www.anaconda.com/pycharm
(base) root@brave-hop-2:~# conda -V
conda 4.6.11
/home/Web/app存放flask项目
本次加入项目目录为
/home/web/app
-static
-templates
-main.py
conda create -n flask python=3.7
conda activate flask
conda install flask
pip install flask_bootstrap
...
mkdir /home/Web
mkdir /home/Web/app
mkdir /home/Web/log
https://blog.csdn.net/weixin_33127753/article/details/84874147
#查看当前系统安装所有版本的gcc
ls /usr/bin/gcc* -l
#如果gcc有5以下的版本,则不用在安装
sudo apt-get install gcc-4.8
#更改gcc系统默认版本
sudo rm /usr/bin/gcc #删除已有软连接
sudo ln -s /usr/bin/gcc-4.8 /usr/bin/gcc #创建指向gcc4.8的软连接
pip install uwsgi
apt-get install vim
vim /home/Web/config.ini
/home/Web/config.ini内容
[uwsgi]
# uwsgi 启动时所使用的地址与端口
socket = 127.0.0.1:10087
# 指向网站目录
chdir = /home/Web/app/
# python 启动程序脚本文件
wsgi-file = main.py
# python 程序内用以启动的 application 变量名
callable = app
# 处理器数
processes = 1
# 线程数
threads = 2
#状态检测地址
stats = 127.0.0.1:9191
这里需要注意的是callable = app,这个app是我们Flask中创建一个application变量名。
先把flask项目放到/home/web/app中
uwsgi /home/Web/config.ini
结果
...
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 166688 bytes (162 KB) for 2 cores
*** Operational MODE: threaded ***
Traceback (most recent call last):
File "main.py", line 2, in
from flask_bootstrap import Bootstrap
ModuleNotFoundError: No module named 'flask_bootstrap'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1859)
spawned uWSGI worker 1 (pid: 1860, cores: 2)
*** Stats server enabled on 127.0.0.1:9191 fd: 10 ***
apt-get install supervisor
which uwsgi
(flask) root@brave-hop-2:~# which uwsgi
/home/anaconda3/envs/flask/bin/uwsgi
vim /etc/supervisor/conf.d/card.conf
/etc/supervisor/conf.d/card.conf内容
[program:card]
command = /home/anaconda3/envs/flask/bin/uwsgi /home/Web/config.ini
directory = /home/Web/app
user = root
startsecs = 3
autostart=true
autorestart=true
redirect_stderr = true
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups = 10
stdout_logfile = /home/Web/log/app.log
commanda内容左边是上面which的结果,右边是uwsgi配置文件路径
若supervisorctl start card不行,则
supervisorctl reread
supervisorctl update
apt-get install nginx
vim /etc/nginx/sites-available/default
server {
listen 80;
listen [::]:80;
root /home/Web/app;
access_log /home/Web/log/access_log;
error_log /home/Web/log/error_log;
server_name xn--1iu29hk7n.top www.xn--1iu29hk7n.top;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:10087; # 指向uwsgi 所应用的内部地址,所有请求将转发给uwsgi 处理
uwsgi_param UWSGI_CHDIR /home/Web/app; # 指向网站根目录
uwsgi_param UWSGI_SCRIPT main:app; # 指定启动程序
}
}
#端口访问
server {
listen 8888;
listen [::]:8888;
root /home/Web/app;
access_log /home/Web/log/access_log;
error_log /home/Web/log/error_log;
server_name 127.0.0.1:8888;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:10087; # 指向uwsgi 所应用的内部地址,所有请求将转发给uwsgi 处理
uwsgi_param UWSGI_CHDIR /home/Web/app; # 指向网站根目录
uwsgi_param UWSGI_SCRIPT main:app; # 指定启动程序
}
}
server_name 便是让nginx监听我面域名uwsgi_pass 为/home/Web/config.ini配置文件中的socket地址
ln -s /etc/nginx/sites-available/default .
service nginx start
如果有问题可以重启一下,然后重新启动nginx,注意要先进入虚拟环境flask
reboot
...
source activate flask
service nginx start
https://blog.csdn.net/qwe511455842/article/details/80373160
https://www.168seo.cn/linux/24490.html
https://blog.csdn.net/weixin_33127753/article/details/84874147**