{"title":"部署清单","version":"6.0","locale":"zh-hans","docname":"howto/deployment/checklist","url":"/zh-hans/6.0/howto/deployment/checklist/","canonical":"https://djangodocs.dev/zh-hans/6.0/howto/deployment/checklist/","summary":"互联网是一个恶劣的环境。在部署你的 Django 项目之前，你应该花一些时间来审查你的配置，要考虑到安全、性能和操作。 Django 包含了许多 安全特性 。一些是内置的并且总保持激活状态，其他的则是可选的因为它们不总是恰当的，或者因为它们不便于之后的开发。举个例子，强制的 HTTPS…","html":"<h1>部署清单<a class=\"heading-anchor\" href=\"#deployment-checklist\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>互联网是一个恶劣的环境。在部署你的 Django 项目之前，你应该花一些时间来审查你的配置，要考虑到安全、性能和操作。</p>\n<p>Django 包含了许多 <a class=\"reference internal\" href=\"/zh-hans/6.0/topics/security/\"><span class=\"doc\">安全特性</span></a>。一些是内置的并且总保持激活状态，其他的则是可选的因为它们不总是恰当的，或者因为它们不便于之后的开发。举个例子，强制的 HTTPS 并不一定适合所有网站，它对于本地开发就是不切实际的。</p>\n<p>性能优化是另一项便利性权衡的主题。例如，缓存在生成环境很有用，但是对本地开发就作用不大。错误报告的需求也大不相同。</p>\n<p>以下清单包括以下配置：</p>\n<ul class=\"simple\">\n<li><p>必须正确地设置 Django 以提供预期的安全级别；</p></li>\n<li><p>期望在每个环境中都是不同的；</p></li>\n<li><p>启用可选的安全功能；</p></li>\n<li><p>启用性能优化；</p></li>\n<li><p>提供错误报告功能。</p></li>\n</ul>\n<p>许多配置项是敏感的，需要被当做机密对待。如果要发布项目源码，常见操作是为开发开放合适的配置项，为生产环境配置私密设置模块。</p>\n<section id=\"run-manage-py-check-deploy\">\n<h2>运行 <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span> <span class=\"pre\">check</span> <span class=\"pre\">--deploy</span></code><a class=\"heading-anchor\" href=\"#run-manage-py-check-deploy\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>下面介绍的某些检查项会自动使用 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/django-admin/#cmdoption-check-deploy\"><code class=\"xref std std-option docutils literal notranslate\"><span class=\"pre\">check</span> <span class=\"pre\">--deploy</span></code></a> 选项。请确保根据选项文档中描述的生产设置文件运行它。</p>\n</section>\n<section id=\"switch-away-from-manage-py-runserver\">\n<h2>退出 <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span> <span class=\"pre\">runserver</span></code><a class=\"heading-anchor\" href=\"#switch-away-from-manage-py-runserver\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/django-admin/#django-admin-runserver\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">runserver</span></code></a> 命令不适用于生产环境。请确保切换到生产就绪的 WSGI 或 ASGI 服务器。有关一些常见选项，请参阅 <a class=\"reference internal\" href=\"/zh-hans/6.0/howto/deployment/wsgi/\"><span class=\"doc\">WSGI 服务器</span></a> 或 <a class=\"reference internal\" href=\"/zh-hans/6.0/howto/deployment/asgi/\"><span class=\"doc\">ASGI 服务器</span></a>。</p>\n</section>\n<section id=\"critical-settings\">\n<h2>关键配置<a class=\"heading-anchor\" href=\"#critical-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"secret-key\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-SECRET_KEY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code></a><a class=\"heading-anchor\" href=\"#secret-key\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><strong>密码必须是一个较长的随机值，且被妥善保存。</strong></p>\n<p>确保生产环境使用的密码并未用于其它环境，且未被提交至版本控制系统。这将减少攻击者获取密码的概率。</p>\n<p>逾期将安全密码硬编码在配置模块中，不然考虑从环境变量加载它:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">os</span>\n\n<span class=\"n\">SECRET_KEY</span> <span class=\"o\">=</span> <span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">environ</span><span class=\"p\">[</span><span class=\"s2\">&quot;SECRET_KEY&quot;</span><span class=\"p\">]</span>\n</code></pre></div>\n<p>或者从一个文件:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">with</span> <span class=\"nb\">open</span><span class=\"p\">(</span><span class=\"s2\">&quot;/etc/secret_key.txt&quot;</span><span class=\"p\">)</span> <span class=\"k\">as</span> <span class=\"n\">f</span><span class=\"p\">:</span>\n    <span class=\"n\">SECRET_KEY</span> <span class=\"o\">=</span> <span class=\"n\">f</span><span class=\"o\">.</span><span class=\"n\">read</span><span class=\"p\">()</span><span class=\"o\">.</span><span class=\"n\">strip</span><span class=\"p\">()</span>\n</code></pre></div>\n<p>如果要轮换密钥，你可以使用 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-SECRET_KEY_FALLBACKS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECRET_KEY_FALLBACKS</span></code></a>：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">os</span>\n\n<span class=\"n\">SECRET_KEY</span> <span class=\"o\">=</span> <span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">environ</span><span class=\"p\">[</span><span class=\"s2\">&quot;CURRENT_SECRET_KEY&quot;</span><span class=\"p\">]</span>\n<span class=\"n\">SECRET_KEY_FALLBACKS</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">environ</span><span class=\"p\">[</span><span class=\"s2\">&quot;OLD_SECRET_KEY&quot;</span><span class=\"p\">],</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>确保及时从 <code class=\"docutils literal notranslate\"><span class=\"pre\">SECRET_KEY_FALLBACKS</span></code> 中删除旧的密钥。</p>\n</section>\n<section id=\"debug\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a><a class=\"heading-anchor\" href=\"#debug\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><strong>永远不要在生产环境打开 debug 开关。</strong></p>\n<p>开发时，你当然要配置 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span> <span class=\"pre\">=</span> <span class=\"pre\">True</span></code></a>，这将方便你在浏览器启用完全回溯功能。</p>\n<p>不过，对于生产环境来说，这真是一个坏主意，因为这会泄露很多超出预期的信息：代码摘要，本地变量，配置项，使用的库，等等。</p>\n</section>\n</section>\n<section id=\"environment-specific-settings\">\n<h2>特定于环境的配置<a class=\"heading-anchor\" href=\"#environment-specific-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"allowed-hosts\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-ALLOWED_HOSTS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ALLOWED_HOSTS</span></code></a><a class=\"heading-anchor\" href=\"#allowed-hosts\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span> <span class=\"pre\">=</span> <span class=\"pre\">False</span></code></a> 时，Django 在未正确配置 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-ALLOWED_HOSTS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ALLOWED_HOSTS</span></code></a> 时无法工作。</p>\n<p>该配置避免你的站点遭受某些 CSRF 攻击。如果使用了通配符，你必须实现自定义的 <code class=\"docutils literal notranslate\"><span class=\"pre\">Host</span></code> HTTP 头，或者确保你不会很容易地遭受此种攻击。</p>\n<p>你还应该配置位于 Django 前面的网络服务器来验证主机。它应该用一个静态错误页面来回应，或者忽略不正确主机的请求，而不是将请求转发给 Django。这样你就可以避免在你的 Django 日志中出现虚假的错误（如果你有配置错误报告的话，也可以用电子邮件）。例如，在 nginx 上，你可以设置一个默认的服务器，在一个未识别的主机上返回“444 No Response”。</p>\n<div class=\"code-block\" data-language=\"nginx\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Nginx</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Nginx code\"><code><span class=\"k\">server</span><span class=\"w\"> </span><span class=\"p\">{</span>\n<span class=\"w\">    </span><span class=\"kn\">listen</span><span class=\"w\"> </span><span class=\"mi\">80</span><span class=\"w\"> </span><span class=\"s\">default_server</span><span class=\"p\">;</span>\n<span class=\"w\">    </span><span class=\"kn\">return</span><span class=\"w\"> </span><span class=\"mi\">444</span><span class=\"p\">;</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n</section>\n<section id=\"caches\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-CACHES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CACHES</span></code></a><a class=\"heading-anchor\" href=\"#caches\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>若使用了缓存，开发环境的连接参数和生产环境可能不同。Djano 默认为每个进程提供 <a class=\"reference internal\" href=\"/zh-hans/6.0/topics/cache/#local-memory-caching\"><span class=\"std std-ref\">本地内存缓存</span></a>，这可能与期望不同。</p>\n<p>缓存服务器一般采用弱验证。确保它们只接受来自你的应用服务器的连接。</p>\n</section>\n<section id=\"databases\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DATABASES</span></code></a><a class=\"heading-anchor\" href=\"#databases\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>生产环境与开发环境的数据库连接参数可能是不同的。</p>\n<p>数据库密码是机密的。你应该像保护 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-SECRET_KEY\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SECRET_KEY</span></code></a> 那样保护它们。</p>\n<p>为了最大限度的安全，确保数据库只为来自你应用的连接提供服务。</p>\n<p>如果你还未为数据库设置备份，现在就做！</p>\n</section>\n<section id=\"email-backend-and-related-settings\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">EMAIL_BACKEND</span></code></a> 和关联配置<a class=\"heading-anchor\" href=\"#email-backend-and-related-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>如果你的站点发送邮件，以下值需要被正确地配置。</p>\n<p>默认情况下，Django 从 <code class=\"docutils literal notranslate\"><span class=\"pre\">webmaster&#64;localhost</span></code> 和 <code class=\"docutils literal notranslate\"><span class=\"pre\">root&#64;localhost</span></code> 发送邮件。然而，某些邮件服务商拒绝来自这些地址的邮件。为了使用不同的发件人地址，修改 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-DEFAULT_FROM_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_FROM_EMAIL</span></code></a> 和 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-SERVER_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SERVER_EMAIL</span></code></a> 配置。</p>\n</section>\n<section id=\"static-root-and-static-url\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a> 和 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-STATIC_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_URL</span></code></a><a class=\"heading-anchor\" href=\"#static-root-and-static-url\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>静态文件由开发服务器自动托管。但在生产环境，你必须定义配置 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a> ， <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> 将会拷贝它们。</p>\n<p>查看 <a class=\"reference internal\" href=\"/zh-hans/6.0/howto/static-files/\"><span class=\"doc\">如何管理静态文件（如图片、JavaScript、CSS）</span></a> 获得更多信息。</p>\n</section>\n<section id=\"media-root-and-media-url\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_ROOT</span></code></a> 和 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-MEDIA_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_URL</span></code></a><a class=\"heading-anchor\" href=\"#media-root-and-media-url\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>媒体文件由用户上传。他们是不可信任的！确保 web 服务器从未尝试解析这些文件。例如，若用户上传了一个 <code class=\"docutils literal notranslate\"><span class=\"pre\">.php</span></code> 文件，web 服务器应该永远不要运行它。</p>\n<p>现在是检查这些文件的备份策略的好时机。</p>\n</section>\n</section>\n<section id=\"https\">\n<h2>HTTPS<a class=\"heading-anchor\" href=\"#https\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>允许用户登录的网站应该强制站点范围的 HTTPS，避免明文传输令牌。在 Django 中，令牌包括账号/密码，会话 cookie 和重置密码的令牌。（如果你用邮件发送重置密码的令牌，那就没什么办法能保护它们。）</p>\n<p>仅保护用户账号或后台等敏感区域是不够的，因为 HTTP 和 HTTPS 使用相同的会话 cookie。Web 服务器必须将所有的 HTTP 重定向至 HTTPS，且只将 HTTPS 的请求转发给 Django。</p>\n<p>若你已经配置了 HTTPS，启用下列配置。</p>\n<section id=\"csrf-cookie-secure\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-CSRF_COOKIE_SECURE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CSRF_COOKIE_SECURE</span></code></a><a class=\"heading-anchor\" href=\"#csrf-cookie-secure\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>将此设置为 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，避免不甚用 HTTP 传输 CSRF cookie。</p>\n</section>\n<section id=\"session-cookie-secure\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-SESSION_COOKIE_SECURE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">SESSION_COOKIE_SECURE</span></code></a><a class=\"heading-anchor\" href=\"#session-cookie-secure\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>将此设置未 <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>，避免不甚用 HTTP 传输会话 cookie。</p>\n</section>\n</section>\n<section id=\"performance-optimizations\">\n<h2>性能优化<a class=\"heading-anchor\" href=\"#performance-optimizations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>配置 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span> <span class=\"pre\">=</span> <span class=\"pre\">False</span></code></a> 会禁用几个仅在开发时有用的功能。另外，你要调整下列配置。</p>\n<section id=\"sessions\">\n<h3>会话<a class=\"heading-anchor\" href=\"#sessions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>建议参考 <span class=\"xref std std-ref\">cached sessions 1</span> 以提升性能。</p>\n<p>如果使用数据库来备份会话，参考  <span class=\"xref std std-ref\">clear old sessions 1</span> 以避免存储不必要的数据。</p>\n</section>\n<section id=\"conn-max-age\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-CONN_MAX_AGE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">CONN_MAX_AGE</span></code></a><a class=\"heading-anchor\" href=\"#conn-max-age\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>开启 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/databases/#persistent-database-connections\"><span class=\"std std-ref\">持久数据库连接</span></a> 会在连接数据库账号耗费了请求处理时间的很大一部分的时候，大大提升速度。</p>\n<p>这对带宽有限的虚拟主机帮助极大。</p>\n</section>\n<section id=\"templates\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-TEMPLATES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TEMPLATES</span></code></a><a class=\"heading-anchor\" href=\"#templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>启用缓存模板加载器通常可以显著提高性能，因为它避免了每次需要呈现模板时都要编译模板。当 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span> <span class=\"pre\">=</span> <span class=\"pre\">False</span></code></a> 时，缓存模板加载器会自动启用。有关更多信息，请参阅 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/templates/api/#django.template.loaders.cached.Loader\" title=\"django.template.loaders.cached.Loader\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.template.loaders.cached.Loader</span></code></a>。</p>\n</section>\n</section>\n<section id=\"error-reporting\">\n<h2>发送错误<a class=\"heading-anchor\" href=\"#error-reporting\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>在你将代码推送至生产环境后，你总是期望代码是健壮的，但你并不能控制意料之外的错误。还好，Django 能捕获错误并通知你。</p>\n<section id=\"logging\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-LOGGING\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGGING</span></code></a><a class=\"heading-anchor\" href=\"#logging\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>在将网站放入生产环境前，检查 logging 配置项。在你收到某些信息后，查看其是否按预期运行。</p>\n<p>查看 <a class=\"reference internal\" href=\"/zh-hans/6.0/topics/logging/\"><span class=\"doc\">日志</span></a> 了解 logging 的细节。</p>\n</section>\n<section id=\"admins-and-managers\">\n<h3><a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code></a> 和 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MANAGERS</span></code></a><a class=\"heading-anchor\" href=\"#admins-and-managers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>发生 500 错误时，会邮件通知 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ADMINS</span></code></a>。</p>\n<p>404 错误会通知 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MANAGERS</span></code></a>。<a class=\"reference internal\" href=\"/zh-hans/6.0/ref/settings/#std-setting-IGNORABLE_404_URLS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">IGNORABLE_404_URLS</span></code></a> 有助于过滤误报。</p>\n<p>参考  <a class=\"reference internal\" href=\"/zh-hans/6.0/howto/error-reporting/\"><span class=\"doc\">如何管理错误报告</span></a> 了解邮件如何在发生错误时发送报告的细节。</p>\n<aside class=\"admonition-error-reporting-by-email-doesn-t-scale-very-well admonition\">\n<p class=\"admonition-title\">利用邮件报告错误的弹性并不好</p>\n<p>在收件箱被报告塞满前，考虑下使用错误监控系统，类似 <a class=\"reference external\" href=\"https://docs.sentry.io/\">Sentry</a>。Sentry 还可以聚合日志。</p>\n</aside>\n</section>\n<section id=\"customize-the-default-error-views\">\n<h3>自定义默认错误视图<a class=\"heading-anchor\" href=\"#customize-the-default-error-views\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Django 包括几个 HTTP 错误代码的默认视图和模板。你可能想覆盖默认模板，在你的根模板目录下创建以下模板：<code class=\"docutils literal notranslate\"><span class=\"pre\">404.html</span></code>、<code class=\"docutils literal notranslate\"><span class=\"pre\">500.html</span></code>、<code class=\"docutils literal notranslate\"><span class=\"pre\">403.html</span></code> 和 <code class=\"docutils literal notranslate\"><span class=\"pre\">400.html</span></code>。使用这些模板的 <a class=\"reference internal\" href=\"/zh-hans/6.0/ref/views/#error-views\"><span class=\"std std-ref\">默认错误视图</span></a> 应该足以满足 99% 的网络应用，但你也可以 <a class=\"reference internal\" href=\"/zh-hans/6.0/topics/http/views/#customizing-error-views\"><span class=\"std std-ref\">自定义它们</span></a>。</p>\n</section>\n</section>","rootId":"deployment-checklist","toc":[{"title":"运行 manage.py check --deploy","anchor":"run-manage-py-check-deploy","children":[]},{"title":"退出 manage.py runserver","anchor":"switch-away-from-manage-py-runserver","children":[]},{"title":"关键配置","anchor":"critical-settings","children":[{"title":"SECRET_KEY","anchor":"secret-key","children":[]},{"title":"DEBUG","anchor":"debug","children":[]}]},{"title":"特定于环境的配置","anchor":"environment-specific-settings","children":[{"title":"ALLOWED_HOSTS","anchor":"allowed-hosts","children":[]},{"title":"CACHES","anchor":"caches","children":[]},{"title":"DATABASES","anchor":"databases","children":[]},{"title":"EMAIL_BACKEND 和关联配置","anchor":"email-backend-and-related-settings","children":[]},{"title":"STATIC_ROOT 和 STATIC_URL","anchor":"static-root-and-static-url","children":[]},{"title":"MEDIA_ROOT 和 MEDIA_URL","anchor":"media-root-and-media-url","children":[]}]},{"title":"HTTPS","anchor":"https","children":[{"title":"CSRF_COOKIE_SECURE","anchor":"csrf-cookie-secure","children":[]},{"title":"SESSION_COOKIE_SECURE","anchor":"session-cookie-secure","children":[]}]},{"title":"性能优化","anchor":"performance-optimizations","children":[{"title":"会话","anchor":"sessions","children":[]},{"title":"CONN_MAX_AGE","anchor":"conn-max-age","children":[]},{"title":"TEMPLATES","anchor":"templates","children":[]}]},{"title":"发送错误","anchor":"error-reporting","children":[{"title":"LOGGING","anchor":"logging","children":[]},{"title":"ADMINS 和 MANAGERS","anchor":"admins-and-managers","children":[]},{"title":"自定义默认错误视图","anchor":"customize-the-default-error-views","children":[]}]}],"breadcrumbs":[{"docname":"howto/index","title":"如何引导","url":"/zh-hans/6.0/howto/"},{"docname":"howto/deployment/index","title":"如何部署 Django","url":"/zh-hans/6.0/howto/deployment/"}],"prev":{"docname":"howto/deployment/asgi/uvicorn","title":"如何使用 Uvicorn 托管 Django","url":"/zh-hans/6.0/howto/deployment/asgi/uvicorn/"},"next":{"docname":"howto/static-files/deployment","title":"如何部署静态文件","url":"/zh-hans/6.0/howto/static-files/deployment/"},"formats":{"html":"/zh-hans/6.0/howto/deployment/checklist/","markdown":"/zh-hans/6.0/howto/deployment/checklist.md","json":"/zh-hans/6.0/howto/deployment/checklist.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/howto/deployment/checklist.txt","official":"https://docs.djangoproject.com/zh-hans/6.0/howto/deployment/checklist/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}