---
title: "How to deploy static files"
version: 4.0
locale: id
source: https://docs.djangoproject.com/id/4.0/howto/static-files/deployment/
canonical: https://djangodocs.dev/id/4.0/howto/static-files/deployment/
---
# How to deploy static files

> **See also**
>
> Untuk perkenalan ke penggunaan [`django.contrib.staticfiles`](/id/4.0/ref/contrib/staticfiles/#module-django.contrib.staticfiles), lihat [How to manage static files (e.g. images, JavaScript, CSS)](/id/4.0/howto/static-files/).

## Melayani berkas statis di produksi

The basic outline of putting static files into production consists of two
steps: run the [`collectstatic`](/id/4.0/ref/contrib/staticfiles/#django-admin-collectstatic) command when static files change, then
arrange for the collected static files directory ([`STATIC_ROOT`](/id/4.0/ref/settings/#std-setting-STATIC_ROOT)) to be
moved to the static file server and served. Depending on
[`STATICFILES_STORAGE`](/id/4.0/ref/settings/#std-setting-STATICFILES_STORAGE), files may need to be moved to a new location
manually or the [`post_process`](/id/4.0/ref/contrib/staticfiles/#django.contrib.staticfiles.storage.StaticFilesStorage.post_process) method of
the `Storage` class might take care of that.

As with all deployment tasks, the devil's in the details. Every production
setup will be a bit different, so you'll need to adapt the basic outline to fit
your needs. Below are a few common patterns that might help.

### Melayani situs dan berkas-berkas tetap anda dari peladen sama

Jika anda ingin melayani berkas-berkas tetap anda dari peladen sama yang sudah melayani situs anda, pengolahan mungkin terlihat sesuatu seperti:

- Dorong kode anda ke atas ke peladen penyebaran.
- Di peladen, jalankan [`collectstatic`](/id/4.0/ref/contrib/staticfiles/#django-admin-collectstatic) untuk menyalin semua berkas statis kedalam [`STATIC_ROOT`](/id/4.0/ref/settings/#std-setting-STATIC_ROOT).
- Konfigurasikan peladen jaringan anda untuk melayani berkas-berkas dalam [`STATIC_ROOT`](/id/4.0/ref/settings/#std-setting-STATIC_ROOT) dibawah URL [`STATIC_URL`](/id/4.0/ref/settings/#std-setting-STATIC_URL). Sebagai contoh, ini [how to do this with Apache and mod\_wsgi](/id/4.0/howto/deployment/wsgi/modwsgi/#serving-files).

Anda mungkin akan ingin mengotomatisasi pengolahan ini, khususnya jika anda mendapatkan banyak peladen jaringan.

### Melayani berkas statis dari sebuah server tersendiri

Most larger Django sites use a separate web server -- i.e., one that's not also
running Django -- for serving static files. This server often runs a different
type of web server -- faster but less full-featured. Some common choices are:

- [Nginx](https://nginx.org/en/)
- Versi ringkas dari [Apache](https://httpd.apache.org/)

Konfigurasi peladen ini diluar cakupan dari dokumen ini; periksa setiap dokumentasi masing-masing peladen untuk perintah.

Sejak peladen berkas tetap anda tidak akan menjalankan Django, anda akan butuh merubah strategi penyebaran menjadi kelihatan sesuatu seperti:

- Ketika berkas statis anda berubah, jalankan [`collectstatic`](/id/4.0/ref/contrib/staticfiles/#django-admin-collectstatic) secara lokal.
- Dorong [`STATIC_ROOT`](/id/4.0/ref/settings/#std-setting-STATIC_ROOT) lokal anda sampai pada peladen berkas tetap kedalam direktori yang sedang dilayani. [rsync](https://rsync.samba.org/) adalah sebuah pilihan umum untuk langkah ini sejak dia hanya butuh memindahkan bit ke berkas-berkas tetap yang telah berubah.

### Melayani berkas statis dari layanan cloud atau CDN

Another common tactic is to serve static files from a cloud storage provider
like Amazon's S3 and/or a CDN (content delivery network). This lets you
ignore the problems of serving static files and can often make for
faster-loading web pages (especially when using a CDN).

Ketika menggunakan layanan ini, alurkerja dasar akan kelihatan sedikit seperti diatas, kecuali bahwa daripada menggunakan `rsync` untuk memindahkan berkas-berkas tetap anda ke peladen anda akan butuh untuk memindahkan berkas-berkas tetap ke penyedia panyimpanan atau CDN.

There's any number of ways you might do this, but if the provider has an API,
you can use a [custom file storage backend](/id/4.0/howto/custom-file-storage/)
to integrate the CDN with your Django project. If you've written or are using a
3rd party custom storage backend, you can tell [`collectstatic`](/id/4.0/ref/contrib/staticfiles/#django-admin-collectstatic) to use
it by setting [`STATICFILES_STORAGE`](/id/4.0/ref/settings/#std-setting-STATICFILES_STORAGE) to the storage engine.

Sebagai contoh, jika anda telah menulis sebuah backend penyimpanan S3 dalam `myproject.storage.S3Storage` anda dapat menggunakannya dengan:

```
STATICFILES_STORAGE = 'myproject.storage.S3Storage'
```

Once that's done, all you have to do is run [`collectstatic`](/id/4.0/ref/contrib/staticfiles/#django-admin-collectstatic) and your
static files would be pushed through your storage package up to S3. If you
later needed to switch to a different storage provider, you may only have to
change your [`STATICFILES_STORAGE`](/id/4.0/ref/settings/#std-setting-STATICFILES_STORAGE) setting.

Untuk rincian pada bagaimana anda menulis satu dari backend ini, lihat [How to write a custom storage class](/id/4.0/howto/custom-file-storage/). Ada aplikasi pihak 3 tersedia yang menyediakan backend penyimpanan untuk banyak API penyimpanan berkas umum. Titik awal bagus adalah [overview at djangopackages.org](https://djangopackages.org/grids/g/storage-backends/).

## Pelajari lagi

Untuk rincian lengkap pada semua pengaturan, perintah, cetakan etiket, dan potongan-potongan lainnya dalam [`django.contrib.staticfiles`](/id/4.0/ref/contrib/staticfiles/#module-django.contrib.staticfiles), lihat [the staticfiles reference](/id/4.0/ref/contrib/staticfiles/).
