<h1>nginx<aclass="headerlink"href="#nginx"title="Link to this heading">¶</a></h1>
<p><aclass="reference external"href="https://nginx.org/">nginx</a> is a fast, production level HTTP server. When serving your
application with one of the WSGI servers listed in <aclass="reference internal"href="index.html"><spanclass="doc">Deploying to Production</span></a>, it is
often good or necessary to put a dedicated HTTP server in front of it.
This “reverse proxy” can handle incoming requests, TLS, and other
security and performance concerns better than the WSGI server.</p>
<p>Nginx can be installed using your system package manager, or a pre-built
executable for Windows. Installing and running Nginx itself is outside
the scope of this doc. This page outlines the basics of configuring
Nginx to proxy your application. Be sure to read its documentation to
understand what features are available.</p>
<sectionid="domain-name">
<h2>Domain Name<aclass="headerlink"href="#domain-name"title="Link to this heading">¶</a></h2>
<p>Acquiring and configuring a domain name is outside the scope of this
doc. In general, you will buy a domain name from a registrar, pay for
server space with a hosting provider, and then point your registrar
at the hosting provider’s name servers.</p>
<p>To simulate this, you can also edit your <codeclass="docutils literal notranslate"><spanclass="pre">hosts</span></code> file, located at
<codeclass="docutils literal notranslate"><spanclass="pre">/etc/hosts</span></code> on Linux. Add a line that associates a name with the
local IP.</p>
<p>Modern Linux systems may be configured to treat any domain name that
ends with <codeclass="docutils literal notranslate"><spanclass="pre">.localhost</span></code> like this without adding it to the <codeclass="docutils literal notranslate"><spanclass="pre">hosts</span></code>
<divclass="code-block-caption"><spanclass="caption-text"><codeclass="docutils literal notranslate"><spanclass="pre">/etc/hosts</span></code></span><aclass="headerlink"href="#id2"title="Link to this code">¶</a></div>
<h2>Configuration<aclass="headerlink"href="#configuration"title="Link to this heading">¶</a></h2>
<p>The nginx configuration is located at <codeclass="docutils literal notranslate"><spanclass="pre">/etc/nginx/nginx.conf</span></code> on
Linux. It may be different depending on your operating system. Check the
docs and look for <codeclass="docutils literal notranslate"><spanclass="pre">nginx.conf</span></code>.</p>
<p>Remove or comment out any existing <codeclass="docutils literal notranslate"><spanclass="pre">server</span></code> section. Add a <codeclass="docutils literal notranslate"><spanclass="pre">server</span></code>
section and use the <codeclass="docutils literal notranslate"><spanclass="pre">proxy_pass</span></code> directive to point to the address the
WSGI server is listening on. We’ll assume the WSGI server is listening
locally at <codeclass="docutils literal notranslate"><spanclass="pre">http://127.0.0.1:8000</span></code>.</p>
<divclass="code-block-caption"><spanclass="caption-text"><codeclass="docutils literal notranslate"><spanclass="pre">/etc/nginx.conf</span></code></span><aclass="headerlink"href="#id3"title="Link to this code">¶</a></div>
<p>Then <aclass="reference internal"href="proxy_fix.html"><spanclass="doc">Tell Flask it is Behind a Proxy</span></a> so that your application uses these headers.</p>