flask+uwsgi+nginx配置
uwsgi文件
[uwsgi]
master = true
socket=127.0.0.1:5000
chdir = /var/app/flask_project
wsgi-file = /var/app/flask_project/app.py
callable = app
pidfile =/var/app/flask_project/uwsgi.pid
processes = 2
threads = 8
buffer-size = 32768
daemonize=/var/app/flask_project/uwsgi.log
nginx
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:5000;
uwsgi_param UWSGI_PYTHON /bin/python3;
uwsgi_param UWSGI_CHDIR /var/app/flask_project;
uwsgi_param UWSGI_SCRIPT app:app;
}
Vue
server {
listen 81;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:5000;
uwsgi_param UWSGI_PYTHON /bin/python3;
uwsgi_param UWSGI_CHDIR /var/app/flask_project;
uwsgi_param UWSGI_SCRIPT app:app;
}
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location / {
root /var/app/flask_vue/dist;
index index.html index.html;
}
location /api {
proxy_pass http://127.0.0.1:81;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
将nginx添加到systemctl中
[Unit]
Description=nginx web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c
/usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
将nginx添加到service中
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
killproc $nginxd -HUP
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
命令
- window下默认编辑完的文本格式为utf-8,放到linux中是不能使用的,需要改为UNIX格式
- 在vim下可以使用 set fileencoding 查看文件的编码格式
- 可以使用 dos2unix工具转换文件格式
- yum install dos2unix
- dos2unix 文件路径
- 重启uwsgi uwsgi --reload uwsgi.pid