1、安装nginx
nginx安装 详情
2、nginx配置
在/etc/nginx/conf.d创建一个名为movie.conf的nginx配置文件,配置内容如下:
server {
listen 80;
server_name 47.98.173.29;
charset utf-8;
access_log /home/app/movie/log/movie.access.log main; # 运行时如果该行提示报错就将此处注释掉,日志路径
error_log /home/app/movie/log/movie.error.log warn; # 错误日志保存路径
location / {
root /home/app/movie;
index index.html index.htm;
include uwsgi_params;
uwsgi_pass 127.0.0.1:5000;
uwsgi_param UWSGI_PYHOME /home/app/flask_env;
uwsgi_param UWSGI_CHDIR /home/app/movie;
uwsgi_param PYTHONPATH /home/app/movie;
uwsgi_param UWSGI_MODULE manage;
uwsgi_param UWSGI_CALLABLE app;
}
}
nginx相关命令
nginx -t -c nginx.conf # 查看配置文件是否有问题的命令
nginx -s reload # 重启nginx
systemctl start nginx.service # 启动nginx服务
systemctl restart nginx.service # 重新启动nginx服务
3、安装uwsgi
uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换。WSGI是一种Web服务器网关接口。它是一个Web服务器(如nginx,uWSGI等服务器)与web应用(如用Flask框架写的程序)通信的一种规范。uwsgi安装命令:
pip install uwsgi
4、uwsgi配置
新建一个uwsgi.ini文件,文件内容如下:
[uwsgi]
enable-theads=true
thunder-lock=true
vhost=true
socket=127.0.0.1:5000
master=true
workers=4
max.requests=128
启动uwsgi:
uwsgi --ini /etc/uwsgi.ini