日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

运用Nginx代理和UWSGI将Flask项目部署在Linux中 详细步骤

發布時間:2023/12/20 linux 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 运用Nginx代理和UWSGI将Flask项目部署在Linux中 详细步骤 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

nginx:
安裝可以參照的路徑:
? http://nginx.org/en/linux_packages.html#Ubuntu

啟動Nginx

?? ?nginx ?? ?[ -c ?configpath] ? 默認配置目錄:/etc/nginx/nginx.conf

查看進程:

?? ?ps -ef |grep nginx

控制Nginx

?? ?nginx -s xxxstop ?? ??? ?快速關閉quit?? ??? ?優雅的關閉reload?? ??? ?重新加載配置

nginx的配置:/etc/nginx/nginx.conf ?----》 nginx默認的啟動文件

cp一個啟動文件到項目目錄中?

配置代碼內容:


user ?root; ? -----》 要與master process名稱保持相同

運行要用絕對路徑
worker_processes ?1;

error_log ?/var/log/nginx/error.log warn;
pid ? ? ? ?/var/run/nginx.pid;


events {
? ? worker_connections ?1024;
}


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;

? ? server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?localhost;

? ? ? ? #charset koi8-r;
? ? ? ? #access_log ?/var/log/nginx/host.access.log ?main;
? ? ? ? ? root ? /home/liu/flask0923; ? -----》 項目目錄

? ? ? ? location /static { ? ?-----》 配置靜態文件
? ? ? ? ? alias ?/home/liu/flask0923/static;
? ? ? ? }

? ? ? ? location / { ? ?------》 python相關的文件 ?對接uwsgi服務器
? ? ? ? ? ? include ?/etc/nginx/uwsgi_params;
? ? ? ? ? ? uwsgi_pass ?localhost:8000; ? -----》 端口號要注意與uwsgi.ini的保持一致
? ? ? ? }


? ? }
}


啟動: nginx -c? +絕對路徑?

如果出現日志log文件錯誤 命令前 加上? sudo!!!!!!!?

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2019/09/25 19:57:51 [warn] 4096#4096: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2 2019/09/25 19:57:51 [notice] 4096#4096: signal process started 2019/09/25 19:57:51 [alert] 4096#4096: kill(3886, 3) failed (1: Operation not permitted)


?

? ? ?nginx -c /home/liu/flask0923/nginx.conf

? ? ?nginx -s quit

? ? ?nginx -s reload

配置: uwsgi

進入虛擬環境 workon中

pip install uwsgi

在項目下:創建uwsgi.ini 文件??!!!!!!!!踩坑用錯會無法監聽80端口

內容:
[uwsgi]
# 使用nginx連接時 使用
# socket = 0.0.0.0:8000

# 直接作為web服務器使用
http = 0.0.0.0:8000

# 配置工程目錄
chdir = /home/running/Documents/day46_blog
wsgi-file = manage.py
# router
callable = app

# 配置項目的wsgi目錄。相對于工程目錄 django
# chdir = /root/shop/aixianfeng
# wsgi-file = aixianfeng/wsgi.py


#配置進程,線程信息
processes = 4

threads = 10

enable-threads = True

master = True

pidfile = uwsgi.pid

daemonize = uwsgi.log

啟動: uwsgi --ini ?/home/running/Documents/day46_blog/uwsgi.ini

停止: uwsgi --stop uwsgi.pid

Nginx.conf

user root; worker_processes 1;error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid;events {worker_connections 1024; }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;server {listen 80;server_name localhost;#charset koi8-r;#access_log /var/log/nginx/host.access.log main;root /home/liu/flask0923;location /static {alias /home/liu/flask0923/static;}location / {include /etc/nginx/uwsgi_params;uwsgi_pass localhost:8000;}#error_page 500 502 503 504 /50x.html;#location = /50x.html {# root /usr/share/nginx/html;#}}}

uwsgi.ini

[uwsgi] # 使用nginx連接時 使用 socket = 0.0.0.0:8000# 直接作為web服務器使用 #http = 0.0.0.0:8000# 配置工程目錄 chdir = /home/liu/flask0923 wsgi-file = manage.py # router callable = app# 配置項目的wsgi目錄。相對于工程目錄 # chdir = /root/shop/flaskday5 # wsgi-file = aixianfeng/wsgi.py#配置進程,線程信息 processes = 4threads = 10enable-threads = Truemaster = Truepidfile = uwsgi.piddaemonize = uwsgi.log

成功啟動uwsgi和nginx 即可將項目成功部署!

root@ubuntu:~# workon flaskenv


(flaskenv) root@ubuntu:~# uwsgi --ini /home/admin/flask0923/uwsgi.ini?

(flaskenv) root@ubuntu:~# nginx -c /home/admin/flask0923/nginx.conf?

總結

以上是生活随笔為你收集整理的运用Nginx代理和UWSGI将Flask项目部署在Linux中 详细步骤的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。