nginx啟動兩個flask項目


准備flask項目

flask_demo

 

flask_demo1

准備uwsgi

  • uWSGI 一個基於自有的uwsgi協議、WSGI協議和http服務協議的web網關
安裝
 pip install uwsgi

uwsgi配置1

[uwsgi]
#源碼目錄
chdir=/home/ubuntu/data/www/flask_demo
#python 虛擬環境
home=/home/ubuntu/data/www/python3_vir
module=flask_demo
callable=app
master=true
processes=2
http=0.0.0.0:9527
socket=/home/ubuntu/data/www/logs/demo.sock
buffer-size=65535
pidfile=/home/ubuntu/data/www/logs/demo.pid
chmod-socket=777
logfile-chmod=644
daemonize=/home/ubuntu/data/www/logs/demo.log

uwsgi配置2

[uwsgi]
#源碼目錄
chdir=/home/ubuntu/data/www/flask_demo1
#python 虛擬環境
home=/home/ubuntu/data/www/python3_vir
module=flask_demo1
callable=app
master=true
processes=2
http=0.0.0.0:8889
socket=/home/ubuntu/data/www/logs/demo1.sock
buffer-size=65535
pidfile=/home/ubuntu/data/www/logs/demo1.pid
chmod-socket=777
logfile-chmod=644
daemonize=/home/ubuntu/data/www/logs/demo1.log

uwsgi啟動兩個項目

uwsgi --ini flask_demo.ini

uwsgi --ini flask_demo1.ini

 

nginx服務配置

nginx是一個開源的,支持高性能,高並發的代理服務軟件
nginx不但是一個優秀的web服務軟件,還可以反向代理和負載均衡,以及緩存服務或使用。

nginx配置
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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;

    keepalive_timeout  65;

    #gzip  on;

    #include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/flask_demo1.conf; include /etc/nginx/demo.d/flask_demo.conf;
}

 

  兩個配置文件
flask_demo.conf

server {
        #listen 80 default backlog=2048;
        listen 443 ssl;
        server_name xx.cn;
        #證書文件名稱
        ssl_certificate demo.d/1_xx.cn_bundle.crt;
        #私鑰文件名稱
        ssl_certificate_key demo.d/2_xx.cn.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        charset UTF-8;
        access_log      /var/log/nginx/myweb_access.log;
        error_log       /var/log/nginx/myweb_error.log;

        client_max_body_size 75M;

        location / {
                try_files $uri @yourapplication1;
        }
      location @yourapplication1 {
      include uwsgi_params;
      uwsgi_pass unix:/home/ubuntu/data/www/logs/demo.sock;
      uwsgi_read_timeout 1800;
      uwsgi_send_timeout 300;
    }
}
server {
        listen 80;
        server_name xx.cn;
        rewrite ^(.*) https://xx.cn$1 permanent;

}

 

flask_demo1.conf
server {
        listen 80 default backlog=2048;
        listen 443 ssl;
        server_name xx.cn;
        #證書文件名稱
        ssl_certificate demo1.d/1_xx.cn_bundle.crt;
        #私鑰文件名稱
        ssl_certificate_key demo1.d/2_xx.cn.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        charset UTF-8;
        access_log      /var/log/nginx/myweb_access1.log;
        error_log       /var/log/nginx/myweb_error1.log;

        client_max_body_size 75M;

        location / {
                try_files $uri @yourapplication;
        }
      location @yourapplication {
      include uwsgi_params;
      uwsgi_pass unix:/home/ubuntu/data/www/logs/demo1.sock;
      uwsgi_read_timeout 1800;
      uwsgi_send_timeout 300;
    }
}

啟動nginx

service nginx restart

 






 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM