django項(xiàng)目怎么部署nginx+uwsgi

DEBUG = False #debug改為falseALLOWED_HOSTS = ['*'] #?訪問地址改為?“*”?表示所有STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR),"static") #nginx訪問的目錄 放到了之前static的上一級(jí)目錄,可以自定義 需要寫絕對(duì)路徑STATIC_URL = '/static/' STATICFILES_DIRS=[ os.path.join(BASE_DIR,"static"),]MEDIA_URL = '/archive/'MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'archive') #用戶上傳的靜態(tài)文件,如:頭像from django.urls import path,re_pathfrom django.conf import settingsfrom django.views.static import serve urlpatterns = [re_path(r'^archive/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}, name='archive'), #用戶上傳的文件?path('favicon.ico', serve,{'path': 'img/favicon.ico','document_root':settings.STATIC_ROOT}), #全局favicon.ico圖標(biāo)] #添加配置選擇?[uwsgi] #配置和nginx連接的socket連接?socket=127.0.0.1:8000 #http=0.0.0.0:8000 #http連接?#配置項(xiàng)目路徑,項(xiàng)目的所在目錄?chdir = /opt/My/Myproject #配置wsgi接口模塊文件路徑,也就是wsgi.py這個(gè)文件所在的目錄名?wsgi-file = Myproject/wsgi.py #配置啟動(dòng)的進(jìn)程數(shù)?processes=4 #配置每個(gè)進(jìn)程的線程數(shù)?threads=2 #配置啟動(dòng)管理主進(jìn)程?master=True #虛擬環(huán)境目錄?home=/opt/My/venv1 #配置存放主進(jìn)程的進(jìn)程號(hào)文件(我注釋了,據(jù)說和supervisor的日志沖突)?#pidfile=uwsgi.pid #配置dump日志記錄 (同上)?#daemonize=uwsgi.log ?user nginx; worker_processes 2; #進(jìn)程數(shù)?error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/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 ngx_core_module.html # for more information. #include /etc/nginx/conf.d/*.conf; server { listen 80;#監(jiān)聽端口?#listen [::]:80 default_server; server_name 192.168.3.119;#?域名或者IP #root /usr/share/nginx/html; # Load configuration files for the default server block. #include /etc/nginx/default.d/*.conf; charset utf-8; location /static { alias /opt/My/static; #靜態(tài)文件地址(STATIC_ROOT)?} location / { include uwsgi_params; uwsgi_pass 0.0.0.0:8000; #項(xiàng)目端口號(hào)?uwsgi_param UWSGI_SCRIPT Myproject.wsgi; #項(xiàng)目wsgi.py目錄?uwsgi_param UWSGI_CHDIR /opt/My/Myproject; #項(xiàng)目目錄?} } }[program:myname] #任務(wù)名?command=/opt/my/venv1/bin/uwsgi --ini /opt/my/venv1/uwsgi.ini #執(zhí)行的命令 運(yùn)行uwsgi。?uwsgi是虛擬環(huán)境內(nèi)的?[program:nginx] ?command=/usr/sbin/nginx #運(yùn)行nginx supervisord -c /etc/supervisord.conf #啟動(dòng)supervisor supervisorctl -c /etc/supervisord.conf #進(jìn)入supervisor交互界面?start myname #啟動(dòng)?\ stop myname #停止?>>?可以寫任務(wù)名稱或者?all?表示全部?restart myname #重啟?/以上就是關(guān)于Centos8下django項(xiàng)目怎么部署nginx+uwsgi的內(nèi)容,如果你們有學(xué)習(xí)到知識(shí)或者技能,可以把它分享出去讓更多的人看到。
了解更多網(wǎng)絡(luò)知識(shí)關(guān)注:http://www.vecloud.com/