大家好,
我在使用 Nginx 在 VPS 伺服器上部署 Flask 應用程式時遇到問題。該應用程式在本地測試以及在 Heroku 上託管時都運作良好。但是,當部署在我的 VPS 上時,任何受 @jwt_required() 保護的路由都會拋出 422 錯誤。
細節:
-
伺服器設定:
- Ubuntu VPS
- Nginx 作為反向代理
- Gunicorn 運行 Flask 應用程式
- Flask-JWT-Extend 用於 JWT 身份驗證
-
有效方法:
- 所有沒有 @jwt_required() 裝飾器的 API 路由都可以完美運作。
- 部署在 Heroku 上時,相同的應用程式可以按預期工作(即使使用 @jwt_required())。
-
失敗之處:
- 在 VPS 設定上使用 @jwt_required() 裝飾器的任何路由都會傳回 422 錯誤。
- 刪除@jwt_required()可以讓路由正常運作。
我嘗試過的事情:
- 已驗證 JWT 令牌是否在授權標頭中正確傳遞。
- 檢查 SECRET_KEY 和令牌過期設定是否不符。
- 確認應用程式使用正確的 ACCESS_TOKEN_EXPIRES 和演算法。
- 使用Postman 和curl 進行測試——沒有區別。
我懷疑這可能與 Nginx 或 Gunicorn 配置有關,但我不知道是什麼。它是否與伺服器處理標頭或 JSON 主體的方式有關?
任何建議或故障排除技巧將不勝感激!
提前致謝!
以上是使用 Nginx 在 VPS 上部署的 Flask 應用程式中出現 @jwt_required() 錯誤的詳細內容。更多資訊請關注PHP中文網其他相關文章!

pythonisehybridmodeLofCompilation和interpretation:1)thepythoninterpretercompilesourcecececodeintoplatform- interpententbybytecode.2)thepythonvirtualmachine(pvm)thenexecutecutestestestestestesthisbytecode,ballancingEaseofuseEfuseWithPerformance。

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允許fordingfordforderynamictynamictymictymictymictyandrapiddefupment,儘管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

在您的知識之際,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations則youneedtoloopuntilaconditionismet

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond

pythonisnotpuroly interpred; itosisehybridablectofbytecodecompilationandruntimeinterpretation.1)PythonCompiLessourceceCeceDintobyTecode,whitsthenexecececected bytybytybythepythepythepythonvirtirtualmachine(pvm).2)

concatenateListSinpythonWithTheSamelements,使用:1)operatoTotakeEpduplicates,2)asettoremavelemavphicates,or3)listcompreanspherensionforcontroloverduplicates,每個methodhasdhasdifferentperferentperferentperforentperforentperforentperfornceandordorimplications。

pythonisanterpretedlanguage,offeringosofuseandflexibilitybutfacingperformancelanceLimitationsInCricapplications.1)drightingedlanguageslikeLikeLikeLikeLikeLikeLikeLikeThonexecuteline-by-line,允許ImmediaMediaMediaMediaMediaMediateFeedBackAndBackAndRapidPrototypiD.2)compiledLanguagesLanguagesLagagesLikagesLikec/c thresst

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Dreamweaver CS6
視覺化網頁開發工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Dreamweaver Mac版
視覺化網頁開發工具

禪工作室 13.0.1
強大的PHP整合開發環境