python开发中前后端部署在同一域名下的静态文件处理

2022年10月31日 18:58 by wst

服务部署

上一篇文章中,在处理静态文件的过程中踩了不少坑。这里做一个总结。

说明:项目前端是vue,项目后端是django。

收集静态文件

1)编译vue后产生的文件夹dist, 先放入后端目录(backend)下。

2)配置settings.py文件,注意包含dist文件夹下的静态文件。


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "dist")],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

注意DIRS设置。

3)把代码放到服务器之后,收集静态文件到static目录下。settings.py中相应的配置如下:

STATIC_URL = '/assets/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "dist/assets"),
]

# 部署时将作为放置静态文件的目录
STATIC_ROOT = 'static'

STATIC_URL这么设置是因为:html拉取静态文件时的地址前缀是"assets"(同时会引起nginx配置更改)。

运行的命令为:

python manage.py collectstatic

4)nginx配置修改,注意静态文件地址。

server {                                                                                                                                                                                                             
    listen 80;                                                                                                                                                                                                       
    server_name prod.eilieili.vip;
    access_log /home/wst/workspace/production-admin/backend/logs/access.log;
    error_log /home/wst/workspace/production-admin/backend/logs/error.log;                                                                                                                                                                     
    client_max_body_size 10M;
    root /home/wst/workspace/production-admin/backend;

        location  /assets/ {
            #如果你的static目录不在root里,可以配置 alias /path/to/your/mysite/static;
            alias /home/wst/workspace/production-admin/backend/static/;
        }

        location / {
            include uwsgi_params; # the uwsgi_params file you installed
            uwsgi_pass 127.0.0.1:5555;
        }
}

注意:location /assets/,常规情况下这里设置为/static/。不要忘了前后的斜杠,否则会报错。还有alias后面的路径,最后也是有斜杠的。

5)对应的uwgi.ini文件为:

[uwsgi]
# 项目根目录路径(full path)
chdir           = /home/ubuntu/workspace/production-admin/backend
# Django的 wsgi 文件
module          = backend.wsgi:application
# virtualenv目录 (full path)
home            = /home/ubuntu/.conda/envs/production
# 自动载入
py-autoreload=1
# 设置日志
daemonize   = %(chdir)/logs/uwsgi.log
log-maxsize = 5000000
master          = true
# 最大工作进程数(CPU密集型建议设为CPU核心数,IO密集型建议设为CPU核心数的两倍)
processes       = 1
# unix套接字文
socket          = %(chdir)/socket.sock
# socket文件权限
chmod-socket    = 777
# 退出时清空环境
vacuum          = true
# 用以重启服务
stats=%(chdir)/uwsgi.status
pidfile=%(chdir)/uwsgi.pid

 


Comments(126) Add Your Comment

Ntxjsv
generic lipitor 10mg <a href="https://lipiws.top/">oral lipitor</a> buy atorvastatin 10mg pill
Ghzrbj
buy ciprofloxacin 1000mg without prescription - <a href="https://cipropro.top/gemyambutol/">myambutol order online</a> where can i buy augmentin
Lfuwrk
order baycip sale - <a href="https://metroagyl.top/">order generic baycip</a> order augmentin 375mg generic
Rzkrfs
buy ciplox generic - <a href="https://septrim.top/doryx/">order doxycycline online</a> erythromycin 500mg cheap
Okfhyh
buy metronidazole 200mg generic - <a href="https://metroagyl.top/">flagyl tablet</a> zithromax 250mg drug
Dkdndy
stromectol uk - <a href="https://keflexin.top/tetracycline/">purchase sumycin sale</a> buy tetracycline generic
Ycbvzr
buy valtrex generic - <a href="https://gnantiviralp.com/diltiazem/">diltiazem canada</a> buy acyclovir online cheap
Xoqsup
acillin without prescription <a href="https://ampiacil.top/doxycyclineantb/">purchase monodox pill</a> order generic amoxicillin
Cmbwyz
flagyl 200mg oral - <a href="https://metroagyl.top/keflexcapsule/">buy amoxicillin online cheap</a> zithromax 500mg pill
Ctzbnw
buy lasix no prescription - <a href="https://antipathogenc.com/prograf/">purchase prograf sale</a> buy generic captopril
Wsfbbc
purchase glucophage generic - <a href="https://gnantiacidity.com/">buy cheap generic glucophage</a> lincocin 500 mg canada
Kyejhc
buy zidovudine paypal - <a href="https://canadiangnp.com/zyloprim/"></a> buy zyloprim pills
Gihjqm
buy clozaril 100mg without prescription - <a href="https://genonlinep.com/frumil/">frumil cost</a> buy famotidine generic
Xxppqd
order seroquel 50mg without prescription - <a href="https://gnkantdepres.com/desyrel/">trazodone 50mg generic</a> order eskalith
Mlbctm
anafranil 50mg price - <a href="https://antdeponline.com/cymbalta/">duloxetine generic</a> buy sinequan online cheap
Tygpzd
buy atarax without prescription - <a href="https://antdepls.com/lexapro/">lexapro generic</a> purchase amitriptyline pills
Vfqkcv
cost augmentin 375mg - <a href="https://atbioinfo.com/ethambutol/">buy myambutol pills</a> ciprofloxacin 1000mg usa
Duqjkk
order amoxicillin pill - <a href="https://atbioxotc.com/erythromycin/">erythromycin usa</a> cipro 500mg over the counter
Twtdwf
generic azithromycin 500mg - <a href="https://gncatbp.com/emetronidazole/">buy metronidazole no prescription</a> cost ciplox 500 mg
Spimto
cleocin 150mg price - <a href="https://cadbiot.com/oxytetracycline/">cheap terramycin 250mg</a> purchase chloramphenicol pill
Dkdode
ivermectin 12mg for humans - <a href="https://antibpl.com/">buy stromectol online</a> order cefaclor
Rkxdyi
cost albuterol 4mg - <a href="https://antxallergic.com/cvallegra/">fexofenadine usa</a> theo-24 Cr 400mg over the counter
Wavhwr
buy medrol without prescription - <a href="https://ntallegpl.com/getazelastine/">astelin drug</a> order azelastine 10 ml without prescription
Ezjawa
buy desloratadine tablets - <a href="https://rxtallerg.com/getaristocort/">triamcinolone 4mg pills</a> albuterol medication
Atgbgu
buy generic micronase for sale - <a href="https://prodeprpl.com/pioglitazone30/">order pioglitazone generic</a> order dapagliflozin without prescription
Mswgpc
order metformin for sale - <a href="https://arxdepress.com/acarbose50/">brand acarbose 25mg</a> order precose pills
Aodtis
buy prandin 2mg online - <a href="https://depressinfo.com/jardiance25/">buy jardiance no prescription</a> jardiance drug
Fanyme
semaglutide 14mg without prescription - <a href="https://infodeppl.com/">order generic rybelsus 14mg</a> order DDAVP spray
Cswkco
buy terbinafine no prescription - <a href="https://treatfungusx.com/">lamisil sale</a> griseofulvin us
Nbsqch
buy ketoconazole 200mg online - <a href="https://antifungusrp.com/">order ketoconazole without prescription</a> how to get sporanox without a prescription
Uqmqfv
famvir online buy - <a href="https://amvinherpes.com/">order famciclovir for sale</a> buy valaciclovir 500mg pill
Rmsvfx
digoxin cost - <a href="https://blpressureok.com/furosemidediuret/">buy generic lasix online</a> buy lasix no prescription
Xrlbjt
metoprolol pill - <a href="https://bloodpresspl.com/telmisartan/">buy micardis 80mg for sale</a> nifedipine drug
Qhfnkm
oral hydrochlorothiazide 25 mg - <a href="https://norvapril.com/bisoprolol/">order bisoprolol 10mg online cheap</a> order zebeta without prescription
Yvaxog
buy nitroglycerin - <a href="https://nitroproxl.com/valsartan/">buy generic valsartan online</a> order valsartan generic
Wyweox
simvastatin poison - <a href="https://canescholest.com/gemfibrozil/">lopid whose</a> lipitor ready
Oqccfh
crestor nanny - <a href="https://antcholesterol.com/caduet5mg/">caduet pills merchant</a> caduet buy avoid
Vpswue
buy viagra professional why - <a href="https://edsildps.com/superavana/">avana steady</a> levitra oral jelly online dead
Jqmuyl
priligy horrible - <a href="https://promedprili.com/fildena/">fildena bile</a> cialis with dapoxetine standard
Oqypmi
cenforce online winter - <a href="https://xcenforcem.com/tadaciptadalafil/">tadacip command</a> brand viagra pills love
Lqvowy
brand cialis rapid - <a href="https://probrandtad.com/">brand cialis yell</a> penisole art
Mpbcqx
brand cialis waist - <a href="https://probrandtad.com/alprostadilonline/">alprostadil castle</a> penisole triumph
Zkmgpv
cialis soft tabs pills crouch - <a href="https://supervalip.com/levitrasoft/">levitra soft sell</a> viagra oral jelly online sparkler
Axdekj
cialis soft tabs pills natural - <a href="https://supervalip.com/viagrasuperactive/">viagra super active online shiver</a> viagra oral jelly online tip
Qrpvdq
dapoxetine accurse - <a href="https://promedprili.com/aurogra/">aurogra immediate</a> cialis with dapoxetine stir
Ldslxd
cenforce online kill - <a href="https://xcenforcem.com/">cenforce rid</a> brand viagra sergeant
Npyhzx
asthma medication pose - <a href="https://bsasthmaps.com/">inhalers for asthma pink</a> inhalers for asthma moral
Stkaze
acne treatment fit - <a href="https://placnemedx.com/">acne treatment vivid</a> acne treatment pale
Lxmbxs
pills for treat prostatitis broom - <a href="https://xprosttreat.com/">prostatitis pills knot</a> pills for treat prostatitis take
Utqbya
treatment for uti talent - <a href="https://amenahealthp.com/">uti treatment massive</a> uti medication tangle
Lraeao
claritin similar - <a href="https://clatadine.top/">loratadine study</a> claritin fashion
Jhxtww
valtrex league - <a href="https://gnantiviralp.com/">valacyclovir online female</a> valacyclovir pills comfortable
Mfqcvn
dapoxetine establish - <a href="https://prilixgn.top/">priligy chair</a> priligy distant
Oeviaf
claritin pills laughter - <a href="https://clatadine.top/">claritin chuckle</a> claritin pills attract
Bnykda
ascorbic acid affection - <a href="https://ascxacid.com/">ascorbic acid laugh</a> ascorbic acid despair
Pfqqih
promethazine lion - <a href="https://prohnrg.com/">promethazine maintain</a> promethazine confidence
Egqmpv
clarithromycin pills brush - <a href="https://gastropls.com/ranitidineonline/">ranitidine lean</a> cytotec pills immediate
Ijrojs
order rabeprazole 10mg online - <a href="https://gastrointesl.com/domperidone/">domperidone 10mg sale</a> order domperidone 10mg pills
Gavkzh
order dulcolax 5 mg online - <a href="https://gastroinfop.com/oxybutynin/">purchase oxybutynin generic</a> liv52 20mg cheap
Hmqoyq
how to buy bactrim - <a href="https://ketiracet.com/">keppra 1000mg drug</a> buy tobramycin 10mg
Zljqib
eukroma order - <a href="https://danaterone.shop/">purchase hydroquinone generic</a> cost dydrogesterone
Krdycn
buy generic fulvicin - <a href="https://fulviseoful.com/">pill fulvicin 250 mg</a> lopid 300 mg usa
Hrnblj
purchase dapagliflozin without prescription - <a href="https://forpaglif.com/">dapagliflozin order</a> precose 50mg generic
Rkogrl
dimenhydrinate 50mg for sale - <a href="https://prasilx.com/">prasugrel 10mg pills</a> risedronate online order
Jsmxjw
vasotec 10mg uk - <a href="https://doxapisin.com/">buy cheap generic doxazosin</a> buy zovirax sale
Xlygaq
etodolac 600 mg generic - <a href="https://cilosetal.com/">purchase pletal without prescription</a> pletal 100 mg cheap
Tbuypx
order piroxicam online - <a href="https://rivastilons.com/">buy exelon 3mg online cheap</a> exelon 6mg drug
Pmpbdv
nootropil online buy - <a href="https://nootquin.com/secnidazole/">order secnidazole sale</a> oral sinemet 20mg
Fkzopf
cost hydrea - <a href="https://hydroydrinfo.com/pentoxifylline/">order trental for sale</a> generic methocarbamol 500mg
Vwiihd
purchase depakote - <a href="https://adepamox.com/acetazolamide/">order diamox 250mg without prescription</a> order topiramate 100mg without prescription
Hbqxhm
disopyramide phosphate over the counter - <a href="https://anorpica.com/chlorpromazine/">buy thorazine paypal</a> buy thorazine 100mg
Rfnwhh
buy cheap spironolactone - <a href="https://aldantinep.com/naltrexone/">buy naltrexone online</a> buy revia online cheap
Uemmgl
buy cyclophosphamide cheap - <a href="https://cycloxalp.com/atomoxetine/">order strattera generic</a> buy vastarel pills for sale
Rnbrmf
buy cyclobenzaprine online cheap - <a href="https://abflequine.com/olanzapine/">order zyprexa online</a> enalapril order online
Ucfqux
order ondansetron generic - <a href="https://azofarininfo.com/oxybutynin/">buy oxytrol paypal</a> requip order online
Aeomii
how to buy ascorbic acid - <a href="https://mdacidinfo.com/lopinavirritonavir/">lopinavir ritonavir online</a> compro for sale online
Nwhhvw
buy durex gel sale - <a href="https://xalaplinfo.com/durexcondoms/">durex condoms where to order</a> xalatan generic
Ojnmgi
where can i buy minoxidil - <a href="https://hairlossmedinfo.com/">rogaine online buy</a> proscar 5mg pill
Sumygp
buy arava 10mg generic - <a href="https://infohealthybones.com/risedronate/">order actonel 35mg online cheap</a> where to buy cartidin without a prescription
Zogfrz
oral calan - <a href="https://infoheartdisea.com/valsartan/">valsartan over the counter</a> purchase tenoretic online
Iyrgrb
buy atenolol online - <a href="https://heartmedinfox.com/clopidogrel/">buy plavix 75mg pill</a> order generic coreg 6.25mg
Lzlvym
buy atorlip - <a href="https://infoxheartmed.com/lisinopril/">purchase zestril online</a> order bystolic pill
Lzmmgm
buy generic gasex over the counter - <a href="https://herbalinfomez.com/diabecon/">diabecon online</a> order generic diabecon
Bzlbfs
buy cheap generic lasuna - <a href="https://infoherbalmz.com/diarex/">diarex sale</a> purchase himcolin online cheap
Nmwgqk
buy norfloxacin paypal - <a href="https://gmenshth.com/">buy generic noroxin</a> buy cheap generic confido
Ecwwxa
cheap speman - <a href="https://spmensht.com/finasteride/">fincar medication</a> order fincar without prescription
Jgkwja
buy finasteride generic - <a href="https://finmenura.com/kamagra/">kamagra brand</a> order alfuzosin 10 mg
Cfhauc
cheap hytrin 1mg - <a href="https://hymenmax.com/dutasteride/">purchase dutasteride pills</a> order priligy 90mg for sale
Nbiahj
trileptal 300mg tablet - <a href="https://trileoxine.com/levothyroxine/">order synthroid 75mcg online cheap</a> buy cheap synthroid
Uoquuw
buy duphalac bottless - <a href="https://duphalinfo.com/mentat/">cheap mentat online</a> order betahistine online
Beitce
cyclosporine online order - <a href="https://asimusxate.com/methotrexate/">order methotrexate pills</a> colcrys price
Ilckwz
deflazacort usa - <a href="https://lazacort.com/brimonidine/">alphagan over the counter</a> buy brimonidine without prescription
Hnwcmc
buy generic besivance over the counter - <a href="https://besifxcist.com/">order besifloxacin online cheap</a> order sildamax generic
Cykunq
cheap neurontin pills - <a href="https://aneutrin.com/">gabapentin 600mg usa</a> azulfidine 500mg tablet
Urngvt
benemid 500 mg ca - <a href="https://bendoltol.com/carbamazepine/">buy tegretol 200mg online cheap</a> order generic carbamazepine 200mg
Tcjhsy
buy celebrex paypal - <a href="https://celespas.com/">buy celecoxib 200mg sale</a> purchase indomethacin online
Aknoid
oral colospa - <a href="https://coloxia.com/">purchase colospa online cheap</a> pletal uk
Nvfker
diclofenac 100mg cheap - <a href="https://dicloltarin.com/aspirin/">order aspirin 75mg online</a> aspirin generic
Gpfqss
buy rumalaya without a prescription - <a href="https://rumaxtol.com/shallaki/">order shallaki pills</a> elavil 10mg price
Dsmulp
purchase mestinon pills - <a href="https://mestonsx.com/asumatriptan/">purchase imitrex</a> buy generic imuran
Cledmu
generic diclofenac - <a href="https://vovetosa.com/">buy cheap diclofenac</a> buy nimodipine without a prescription
Kfqkoe
buy ozobax medication - <a href="https://baclion.com/">baclofen 10mg brand</a> order piroxicam 20 mg generic
Uhcxpm
order periactin generic - <a href="https://periheptadn.com/">periactin 4 mg cost</a> buy zanaflex online cheap
Whzqel
meloxicam over the counter - <a href="https://meloxiptan.com/">mobic 7.5mg drug</a> order toradol 10mg without prescription
Wiphrp
buy generic cefdinir 300mg - <a href="https://omnixcin.com/aminocycline/"></a> buy cleocin without a prescription
Wrxddh
isotretinoin 40mg for sale - <a href="https://aisotane.com/asavlosulfon/">buy generic dapsone online</a> deltasone 20mg cheap
Avkpob
purchase prednisone for sale - <a href="https://apreplson.com/prednisolone/">order omnacortil generic</a> buy zovirax cream for sale
Zipifo
order permethrin generic - <a href="https://actizacs.com/asbenzac/">benzac cheap</a> buy generic retin over the counter
Mstssd
betamethasone 20gm over the counter - <a href="https://betnoson.com/">purchase betamethasone without prescription</a> oral benoquin
Eykgod
metronidazole 200mg ca - <a href="https://ametronles.com/">oral metronidazole</a> cenforce 100mg usa
Poache
augmentin 375mg brand - <a href="https://baugipro.com/">augmentin without prescription</a> buy levothroid generic
Ltbmdn
brand cleocin - <a href="https://indometnp.com/">buy indomethacin generic</a> indocin 75mg capsule
Llkxgm
order losartan - <a href="https://acephacrsa.com/">buy keflex online</a> cheap keflex 125mg
Tcvnai
eurax cream - <a href="https://aeuracream.com/">eurax cheap</a> aczone drug
Qujrmw
modafinil us - <a href="https://sleepagil.com/phenergan/">purchase phenergan pill</a> order meloset without prescription
Rtbtgl
bupropion price - <a href="https://bupropsl.com/ayurslim/">order ayurslim online cheap</a> buy shuddha guggulu online
Vfvmlg
xeloda 500mg uk - <a href="https://xelocap.com/naproxen/">buy naproxen 500mg without prescription</a> danocrine 100 mg sale
Nrlsii
progesterone 100mg price - <a href="https://apromid.com/clomipheneferto/">buy fertomid</a> cheap fertomid generic
Kmihto
order alendronate generic - <a href="https://pilaxmax.com/tamoxifen/">cost nolvadex 10mg</a> provera ca
Ilgoxb
aygestin usa - <a href="https://norethgep.com/bimatoprost/">buy lumigan generic</a> yasmin pills
Ljddgs
yasmin cost - <a href="https://festrolp.com/letrozole/">order generic letrozole 2.5 mg</a> buy arimidex 1mg for sale
Hecsyy
how to buy cabergoline - <a href="https://adostilin.com/cabgolin/">purchase cabgolin for sale</a> order alesse pills
Lgmosc
プレドニン通販 - <a href="https://jpaonlinep.com/">プレドニン 副作用</a> アジスロマイシン錠 500mg 強さ
Cpaldg
г‚·гѓ«гѓ‡гѓЉгѓ•г‚Јгѓ« её‚иІ© гЃЉгЃ™гЃ™г‚Ѓ - <a href="https://jpedpharm.com/">г‚·гѓ«гѓ‡гѓЉгѓ•г‚Јгѓ«йЂљиІ©гЃЉгЃ™гЃ™г‚Ѓ</a> г‚·г‚ўгѓЄг‚№ гЃЉгЃ™гЃ™г‚Ѓ
Ynfdod
プレドニン 飲み方 - <a href="https://jpanfarap.com/">プレドニン処方</a> イソトレチノインの飲み方と効果
Hrxjme
eriacta speed - <a href="https://eriagra.com/fforzestf/">forzest solution</a> forzest change