-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30754eb
commit 30c7084
Showing
25 changed files
with
942 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Layout from "@/components/Layout"; | ||
import Button from "@/components/Common/button"; | ||
import Section from "@/components/Common/section"; | ||
import Alert from "@/components/Common/alert"; | ||
import Tabs from "@/components/Common/tab"; | ||
import Step from "@/components/Common/step"; | ||
import Card from "@/components/Common/card"; | ||
import Important from "@/components/Common/important"; | ||
import Highlight from "react-highlight"; | ||
import Link from "next/link"; | ||
import NextPage from "@/components/Common/nextpage"; | ||
import {GoArrowLeft,} from "react-icons/go"; | ||
|
||
<Layout> | ||
# رفع خطای CORS فایلهای Media در برنامههای Django | ||
<hr className="mb-2" /> | ||
|
||
فایلهای رسانه (Media) به کاربران در پلتفرم Django با وبسرور Nginx ارائه میشود؛ حال، اگر کاربرانتان برای دسترسی به فایلهای رسانه با خطای CORS مواجه شدند باید تنظیمات Nginx پروژهی خود را شخصیسازی کنید. | ||
|
||
برای رفع این خطا، یک فایل با نام <Important>liara_nginx.conf</Important> در مسیر اصلی پروژهی خود ایجاد کرده و قطعهکد زیر را در آن، قرار دهید: | ||
<div className="h-2" /> | ||
<div dir='ltr'> | ||
<Highlight className="python"> | ||
{`client_max_body_size 100M; | ||
location /media { | ||
add_header Access-Control-Allow-Origin *; | ||
alias /usr/src/app/media; | ||
} | ||
location /static { | ||
alias /usr/src/app/staticfiles; | ||
} | ||
location / { | ||
try_files /dev/null @django_app; | ||
} | ||
location ~\\.sqlite3$ { | ||
deny all; | ||
error_page 403 =404 /; | ||
} | ||
location ~ /\\.well-known { | ||
allow all; | ||
}`} | ||
</Highlight> | ||
</div> | ||
<div className="h-2" /> | ||
سپس، برنامه خود را مجدداً در لیارا مستقر کنید تا تغییرات، اعمال شوند. | ||
|
||
با اعمال این پیکربندی، فایلهای قرار گرفته در پوشهی <Important>media</Important> با هدر <Important>Access-Control-Allow-Origin</Important> و مقدار <Important>*</Important> سرو میشوند. همچنین شما میتوانید مقدار دلخواه خودتان را نیز، تنظیم کنید. | ||
|
||
|
||
</Layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.