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

> **See also**
>
> Para uma introdução ao uso de [`django.contrib.staticfiles`](/pt-br/5.1/ref/contrib/staticfiles/#module-django.contrib.staticfiles), veja [How to manage static files (e.g. images, JavaScript, CSS)](/pt-br/5.1/howto/static-files/).

## Servindo arquivos estáticos em produção

The basic outline of putting static files into production consists of two
steps: run the [`collectstatic`](/pt-br/5.1/ref/contrib/staticfiles/#django-admin-collectstatic) command when static files change, then
arrange for the collected static files directory ([`STATIC_ROOT`](/pt-br/5.1/ref/settings/#std-setting-STATIC_ROOT)) to be
moved to the static file server and served. Depending on the `staticfiles`
[`STORAGES`](/pt-br/5.1/ref/settings/#std-setting-STORAGES) alias, files may need to be moved to a new location
manually or the [`post_process`](/pt-br/5.1/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.

### Servindo o site e os arquivos estáticos de um mesmo servidor.

Se você quer servir arquivos estáticos do mesmo servidor que já está servindo seu site , o processo talvez se pareça com algo como:

- Envie seu código para o servidor de deploy.
- No servidor, execute: [`collectstatic`](/pt-br/5.1/ref/contrib/staticfiles/#django-admin-collectstatic) para copiar todos os arquivos estáticos para dentro de [`STATIC_ROOT`](/pt-br/5.1/ref/settings/#std-setting-STATIC_ROOT).
- Configure seu servidor Web para servir seus arquivos em [`STATIC_ROOT`](/pt-br/5.1/ref/settings/#std-setting-STATIC_ROOT) sob a URL [`STATIC_URL`](/pt-br/5.1/ref/settings/#std-setting-STATIC_URL). Por exemplo, aqui [como fazer isso com Apache e mod\_wsgi](/pt-br/5.1/howto/deployment/wsgi/modwsgi/#serving-files).

Você irá provavelmente querer automatizar o processo, especialmente se você possuir múltiplos servidores web.

### Servindo arquivos estáticos atráves de um servidor dedicado

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/)
- Uma versão mais enxuta do [Apache](https://httpd.apache.org/)

A configuração destes servidores estão fora do escopo deste documento; verifique a respectiva documentação de cada um para instruções.

Já que seu servidor de arquivos estáticos não irão rodar um Django, você irá precisar modificar a estratégia para algo como:

- Quando seus arquivos estáticos mudarem, execute [`collectstatic`](/pt-br/5.1/ref/contrib/staticfiles/#django-admin-collectstatic)  localmente.
- Coloque seu  [`STATIC_ROOT`](/pt-br/5.1/ref/settings/#std-setting-STATIC_ROOT) local no servidor de arquivo estático dentro do diretório que esta sendo servido. O  [rsync](https://rsync.samba.org/) é uma opção comum para este passo já que ele precisa transferir somente as partes dos arquivos estáticos quesofreram mudanças.

### Servindo arquivos estáticos de um serviço em nuvem ou 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).

Quando usar estes serviços, o processo básico será parecido como o acima, exceto que no lugar de usar o `rsync` para transferir seus arquivos estáticos para o servidor, você irá precisa transferir os arquivos estáticos para fornecedor do armazenamento ou 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](/pt-br/5.1/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`](/pt-br/5.1/ref/contrib/staticfiles/#django-admin-collectstatic) to use
it by setting `staticfiles` in [`STORAGES`](/pt-br/5.1/ref/settings/#std-setting-STORAGES).

Por exemplo, se você escreveu um backend de armazenamento para o S3 em `myproject.storage.S3Storage` você poderia ele com:

```
STORAGES = {
    # ...
    "staticfiles": {"BACKEND": "myproject.storage.S3Storage"}
}
```

Once that’s done, all you have to do is run [`collectstatic`](/pt-br/5.1/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 `staticfiles` in the [`STORAGES`](/pt-br/5.1/ref/settings/#std-setting-STORAGES) setting.

Para detalhes sobre como escrever um destes backends, veja [Como escrever uma classe de armazenamento customizada](/pt-br/5.1/howto/custom-file-storage/). Existem aplicações de terceiros disponíveis que fornecem backends de armazenamento para muitas APIs comuns de armazenamento comuns. Um bom começo é uma  [olhada geral no djangopackages.com](https://www.djangopackages.com/grids/g/storage-backends/).

## Aprenda mais

Para detalhes completos sobre todas as configurações, comandos, tags de templates, e outras partes incluidas em [`django.contrib.staticfiles`](/pt-br/5.1/ref/contrib/staticfiles/#module-django.contrib.staticfiles), veja  [a referencia de arquivos estáticos](/pt-br/5.1/ref/contrib/staticfiles/).
