{"title":"Come usare Django con uWSGI","version":"6.1","locale":"it","docname":"howto/deployment/wsgi/uwsgi","url":"/it/6.1/howto/deployment/wsgi/uwsgi/","canonical":"https://djangodocs.dev/it/6.1/howto/deployment/wsgi/uwsgi/","summary":"uWSGI è un application server container veloce, autoriparante e developer/sysadmin-friendly programmato in C puro.","html":"<h1>Come usare Django con uWSGI<a class=\"heading-anchor\" href=\"#how-to-use-django-with-uwsgi\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p><a class=\"reference external\" href=\"https://uwsgi-docs.readthedocs.io/\">uWSGI</a> è un application server container veloce, autoriparante e developer/sysadmin-friendly programmato in C puro.</p>\n<aside class=\"admonition admonition-seealso\" role=\"note\">\n<p class=\"admonition-title\">Vedi anche</p>\n<p>Il documento uWSGI offre un <a class=\"reference external\" href=\"https://uwsgi.readthedocs.io/en/latest/tutorials/Django_and_nginx.html\">tutorial</a> che copre Django, nginx e uWSGI (un possibile setup di deployment tra molti). I documenti qui sotto sono focalizzati su come integrare Django con uWSGI.</p>\n</aside>\n<section id=\"prerequisite-uwsgi\">\n<h2>Prerequisiti: uWSGI<a class=\"heading-anchor\" href=\"#prerequisite-uwsgi\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Il wiki uWSGI descrive molte <a class=\"reference external\" href=\"https://uwsgi-docs.readthedocs.io/en/latest/Install.html\">procedure di installazione</a>. Usando pip, il package manager di Python, puoi installare qualsiasi versione di uWSGI con un singolo comando. Per esempio:</p>\n<div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</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=\"Shell code\"><code><span class=\"gp\"># </span>Install current stable version.\n<span class=\"gp\">$ </span>python -m pip install uwsgi\n</code></pre></div>\n<section id=\"uwsgi-model\">\n<h3>modello uWSGI<a class=\"heading-anchor\" href=\"#uwsgi-model\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>uWSGI oprera su un modello client-server. Il tuo web server (per es. Apache nginx) comunica con un processo «worker» <code class=\"docutils literal notranslate\">django-uwsgi</code> per servire il contenuto dinamico.</p>\n</section>\n<section id=\"configuring-and-starting-the-uwsgi-server-for-django\">\n<h3>Configurare ed avviare il server uWSGI per Django<a class=\"heading-anchor\" href=\"#configuring-and-starting-the-uwsgi-server-for-django\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>uWSGi supporta diverse modalità di configurazione. Leggi la <a class=\"reference external\" href=\"https://uwsgi.readthedocs.io/en/latest/Configuration.html\">configuration documentation</a> di uWSGI.</p>\n<p>Here’s an example command to start a uWSGI server:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</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=\"Shell code\"><code>uwsgi --chdir<span class=\"o\">=</span>/path/to/your/project <span class=\"se\">\\</span>\n    --module<span class=\"o\">=</span>mysite.wsgi:application <span class=\"se\">\\</span>\n    --env <span class=\"nv\">DJANGO_SETTINGS_MODULE</span><span class=\"o\">=</span>mysite.settings <span class=\"se\">\\</span>\n    --master --pidfile<span class=\"o\">=</span>/tmp/project-master.pid <span class=\"se\">\\</span>\n    --socket<span class=\"o\">=</span><span class=\"m\">127</span>.0.0.1:49152 <span class=\"se\">\\ </span>     <span class=\"c1\"># can also be a file</span>\n    --processes<span class=\"o\">=</span><span class=\"m\">5</span> <span class=\"se\">\\ </span>                <span class=\"c1\"># number of worker processes</span>\n    --uid<span class=\"o\">=</span><span class=\"m\">1000</span> --gid<span class=\"o\">=</span><span class=\"m\">2000</span> <span class=\"se\">\\ </span>        <span class=\"c1\"># if root, uwsgi can drop privileges</span>\n    --harakiri<span class=\"o\">=</span><span class=\"m\">20</span> <span class=\"se\">\\ </span>                <span class=\"c1\"># respawn processes taking more than 20 seconds</span>\n    --max-requests<span class=\"o\">=</span><span class=\"m\">5000</span> <span class=\"se\">\\ </span>          <span class=\"c1\"># respawn processes after serving 5000 requests</span>\n    --vacuum <span class=\"se\">\\ </span>                     <span class=\"c1\"># clear environment on exit</span>\n    --home<span class=\"o\">=</span>/path/to/virtual/env <span class=\"se\">\\ </span>  <span class=\"c1\"># optional path to a virtual environment</span>\n    --daemonize<span class=\"o\">=</span>/var/log/uwsgi/yourproject.log      <span class=\"c1\"># background the process</span>\n</code></pre></div>\n<p>Si assume che tu abbia un top-level package denominato «mysite», ed all’interno un modulo :file`mysitewsgi.py` contenente un oggetto WSGI <code class=\"docutils literal notranslate\">application</code>. Questo è il layout che si ottiene eseguendo <code class=\"docutils literal notranslate\">django-admin startproject mysite</code> (utilizzando lo specifico nome del tuo progetto al posto di <code class=\"docutils literal notranslate\">mysite</code>) con una versione recente di Django. Nel caso il file non esista, verrà creato. Vedi anche il documento <a class=\"reference internal\" href=\"/it/6.1/howto/deployment/wsgi/\"><span class=\"doc\">Come distribuire con WSGI.</span></a> per i contenuti di default che dovrai inserire in questo file e che cos’altro puoi aggiungere in esso.</p>\n<p>Le opzioni specifiche per Django sono qui:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">chdir</code>: il percorso alla directory che necessita di essere sul percorso di importazione di Python – cioè, la directory che contiene il package <code class=\"docutils literal notranslate\">mysite</code>.</p></li>\n<li><p><code class=\"docutils literal notranslate\">module</code>: il modulo WSGI da usare – probabilmente il modulo <code class=\"docutils literal notranslate\">mysite.wsgi</code> che <a class=\"reference internal\" href=\"/it/6.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\">startproject</code></a> crea.</p></li>\n<li><p><code class=\"docutils literal notranslate\">env</code>: dovrebbe probabilmente contenere almeno <span class=\"target\" id=\"index-2\"></span><a class=\"reference internal\" href=\"/it/6.1/topics/settings/#envvar-DJANGO_SETTINGS_MODULE\"><code class=\"xref std std-envvar docutils literal notranslate\">DJANGO_SETTINGS_MODULE</code></a>.</p></li>\n<li><p><code class=\"docutils literal notranslate\">home</code>: Path opzionale dell’ambiente virtuale del tuo progetto</p></li>\n</ul>\n<p>Example ini configuration file:</p>\n<div class=\"code-block\" data-language=\"ini\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Ini</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=\"Ini code\"><code><span class=\"k\">[uwsgi]</span>\n<span class=\"na\">chdir</span><span class=\"o\">=</span><span class=\"s\">/path/to/your/project</span>\n<span class=\"na\">module</span><span class=\"o\">=</span><span class=\"s\">mysite.wsgi:application</span>\n<span class=\"na\">master</span><span class=\"o\">=</span><span class=\"s\">True</span>\n<span class=\"na\">pidfile</span><span class=\"o\">=</span><span class=\"s\">/tmp/project-master.pid</span>\n<span class=\"na\">vacuum</span><span class=\"o\">=</span><span class=\"s\">True</span>\n<span class=\"na\">max-requests</span><span class=\"o\">=</span><span class=\"s\">5000</span>\n<span class=\"na\">daemonize</span><span class=\"o\">=</span><span class=\"s\">/var/log/uwsgi/yourproject.log</span>\n</code></pre></div>\n<p>Example ini configuration file usage:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</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=\"Shell code\"><code>uwsgi --ini uwsgi.ini\n</code></pre></div>\n<aside class=\"admonition-fixing-unicodeencodeerror-for-file-uploads admonition\" role=\"note\">\n<p class=\"admonition-title\">Correggere <code class=\"docutils literal notranslate\">UnicodeEncodeError</code> per il caricamento di file</p>\n<p>If you get a <code class=\"docutils literal notranslate\">UnicodeEncodeError</code> when uploading files with file names\nthat contain non-ASCII characters, make sure uWSGI is configured to accept\nnon-ASCII file names by adding this to your <code class=\"docutils literal notranslate\">uwsgi.ini</code>:</p>\n<div class=\"code-block\" data-language=\"ini\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Ini</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=\"Ini code\"><code><span class=\"na\">env</span> <span class=\"o\">=</span> <span class=\"s\">LANG=en_US.UTF-8</span>\n</code></pre></div>\n<p>Vedi la sezione <a class=\"reference internal\" href=\"/it/6.1/ref/unicode/#unicode-files\"><span class=\"std std-ref\">Files</span></a> nella guida di riferimento Unicode per dettagli.</p>\n</aside>\n<p>Vedi la documentazione uWSGI su come <a class=\"reference external\" href=\"https://uwsgi-docs.readthedocs.io/en/latest/Management.html\">gestire il processo uWSGI</a> per informazioni su come avviare, fermare e ricaricare i worker uWSGI.</p>\n</section>\n</section>","rootId":"how-to-use-django-with-uwsgi","toc":[{"title":"Prerequisiti: uWSGI","anchor":"prerequisite-uwsgi","children":[{"title":"modello uWSGI","anchor":"uwsgi-model","children":[]},{"title":"Configurare ed avviare il server uWSGI per Django","anchor":"configuring-and-starting-the-uwsgi-server-for-django","children":[]}]}],"breadcrumbs":[{"docname":"howto/index","title":"How-to guides","url":"/it/6.1/howto/"},{"docname":"howto/deployment/index","title":"Come distribuire Django","url":"/it/6.1/howto/deployment/"},{"docname":"howto/deployment/wsgi/index","title":"Come distribuire con WSGI.","url":"/it/6.1/howto/deployment/wsgi/"}],"prev":{"docname":"howto/deployment/wsgi/gunicorn","title":"Come installare Django con Gunicorn","url":"/it/6.1/howto/deployment/wsgi/gunicorn/"},"next":{"docname":"howto/deployment/wsgi/modwsgi","title":"Come usare Django con Apache e mod_wsgi","url":"/it/6.1/howto/deployment/wsgi/modwsgi/"},"formats":{"html":"/it/6.1/howto/deployment/wsgi/uwsgi/","markdown":"/it/6.1/howto/deployment/wsgi/uwsgi.md","json":"/it/6.1/howto/deployment/wsgi/uwsgi.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/howto/deployment/wsgi/uwsgi.txt","official":"https://docs.djangoproject.com/it/6.1/howto/deployment/wsgi/uwsgi/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}