0Pricing
Django Academy · レッスン

Reverse ProxyとしてのNginx

Gunicornの前段に置き、静的ファイルを配信します

「Reverse ProxyとしてのNginx」はCoddyKit上の無料Django Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDjango Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Django Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Why Add Nginx

Gunicorn runs your code, but it should not face the raw internet alone. A reverse proxy sits in front and shields it. 🛡️

What a Reverse Proxy Does

A reverse proxy receives every browser request, then forwards it to Gunicorn and relays the answer back. The client never talks to Gunicorn directly.

Nginx Is Fast at Files

Nginx excels at serving static files and handling thousands of connections, freeing Gunicorn to focus only on dynamic Python work.

The Two-Layer Stack

The flow becomes browser to Nginx to Gunicorn to Django. Each layer does what it is best at, giving you speed and safety together.

A Server Block

Nginx config lives in a server block. It listens on a port and names the domain it answers for.

server {
    listen 80;
    server_name example.com;
}

Proxy to Gunicorn

Inside a location, proxy_pass tells Nginx where to send dynamic requests, usually Gunicorn on a local port or socket.

location / {
    proxy_pass http://127.0.0.1:8000;
}

Pass Real Headers

Add proxy_set_header lines so Django sees the true host and client IP, not just Nginx's local address.

proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;

Serve Static Directly

Map a location for /static/ to your collected files. Nginx serves them straight from disk, skipping Gunicorn entirely for speed.

location /static/ {
    alias /app/staticfiles/;
}

Where to Connect

Nginx can reach Gunicorn over a TCP port or a faster Unix socket. Sockets avoid network overhead on the same machine.

Test Before Reload

Always check your config with nginx -t before reloading. A bad file caught here saves you from taking the site offline.

nginx -t
systemctl reload nginx

TLS Lives Here Too

Nginx is also the natural place to terminate HTTPS, decrypting traffic once before passing plain requests on to Gunicorn.

Quick Check

Pick the directive that forwards requests to Gunicorn.

Recap

You set up Nginx as a reverse proxy: it fronts Gunicorn with proxy_pass, serves static files fast, forwards headers, and handles HTTPS. 🎯

よくある質問

「Reverse ProxyとしてのNginx」レッスンは無料ですか?

はい。「Reverse ProxyとしてのNginx」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Django Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Django Academyコースには全4レッスンが含まれています。

「Reverse ProxyとしてのNginx」で何を学びますか?

Gunicornの前段に置き、静的ファイルを配信します ブラウザで直接実行するハンズオンコードでDjango Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Django Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDjango Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「Reverse ProxyとしてのNginx」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDjango Academyレッスンでコードを書いて実行できますか?

はい。すべてのDjango Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. WSGI ServerとしてのGunicorn
  2. Reverse ProxyとしてのNginx
  3. 静的ファイル用のWhiteNoise
  4. Environment VariablesとSettingsの分割
← Django Academyに戻る