uwsgi+nginx+MySQL

1 mysql远程连接

在安装好MySQL的系统中(我的是centOS),启动MySQL,然后输入下面的语句:

grant all privileges  on *.* to root@'%' identified by "root";  by后面的root为密码,可自己设置
FLUSH RIVILEGES;

2 uwsgi

我是放在项目根目录下的,名为xxxx.ini,代码为:

[uwsgi]
socket = 127.0.0.1:8001     
chdir = /root/Online-Registration 
wsgi-file = manage.py  
callable = app
processes = 4
enable-threads = true  启动线程
threads = 2 
stats = 127.0.0.1:9191

参考网站:https://stackoverflow.com/questions/48744884/setting-flask-app-with-uwsgi-and-nginx-in-docker-container

启动命令:uwsgi xxxx.ini
停止命令:sudo killall -9 uwsgi

3. nginx

/etc/nginx/nginx.conf代码:

# For more information on configuration, see:
 #   * Official English Documentation: http://nginx.org/en/docs/
 #   * Official Russian Documentation: http://nginx.org/ru/docs/
 # user nginx;
user root;  取得权限,否则会报403错误
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
 # Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections  1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    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;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/default.conf 代码:

 #
 # The default server
 #
 #server {
 #    listen       80 default_server;
 #    listen       [::]:80 default_server;
 #    server_name  _;
 #    root         /usr/share/nginx/html;
 #
 #    # Load configuration files for the default server block.
 #    include /etc/nginx/default.d/*.conf;
 #
 #    location / {
 #    }
 #
 #    error_page 404 /404.html;
 #        location = /40x.html {
 #    }
 #
 #    error_page 500 502 503 504 /50x.html;
 #        location = /50x.html {
 #    }
 #
 #}
server{
    listen 80;
    server_name 47.100.110.131;
    index /root/Online-Registration/app/templates/registration/index.html;
    rewrite ^/$ / break;
    error_log  /root/Online-Registration/logs/error.log;
    location /static {
        alias /root/Online-Registration/app/static;
    }
    location / {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:8001;
    uwsgi_param UWSGI_PYHOME /root/Online-Registration/venv; # vent dir
    uwsgi_param UWSGI_CHDIR /root/Online-Registration; # root dir
    uwsgi_param UWSGI_SCRIPT manage:app;
    }
 #   location /static/ {
 #  include /etc/nginx/mime.types;
 #       alias /root/Online-Registration/app/static; # amend as required
 #   }
 }

service nginx start
service nginx reload
service nginx stop

参考网站:http://blkstone.github.io/2016/05/04/flask-uwsgi-nginx-deployment/
参考网站:https://juejin.im/entry/58eb912c8d6d810061908b90
参考网站:https://segmentfault.com/a/1190000004294634
参考网站:https://www.jianshu.com/p/8faaec75b813

4. nohup command &

关闭shell终端后,导致邮件无法发送,故我猜想是不是因为关闭了终端,同时uwsgi的启动失效了即多线程没有启动(邮件功能采用了多线程),使用了

nohup uwsgi Online-Registration/uwsgiconfig.ini &
这条命令后再关闭终端,测试邮件功能成功,果不其然是多线程被关闭的原因。

参考网站:https://blog.csdn.net/v1v1wang/article/details/6855552
参考关键字:uwsgi 退出后多线程开启

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值