{"title":"How to deploy static files","version":"4.1","locale":"el","docname":"howto/static-files/deployment","url":"/el/4.1/howto/static-files/deployment/","canonical":"https://djangodocs.dev/el/4.1/howto/static-files/deployment/","summary":"Δείτε επίσης Για μια εισαγωγή στη χρήση του module django.contrib.staticfiles , δείτε στο άρθρο Διαχειρίζοντας τα static files (πχ εικόνες, JavaScript, CSS κλπ) .…","html":"<h1>How to deploy static files<a class=\"heading-anchor\" href=\"#how-to-deploy-static-files\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<aside class=\"admonition admonition-seealso\">\n<p class=\"admonition-title\">Δείτε επίσης</p>\n<p>Για μια εισαγωγή στη χρήση του module <a class=\"reference internal\" href=\"/el/4.1/ref/contrib/staticfiles/#module-django.contrib.staticfiles\" title=\"django.contrib.staticfiles: An app for handling static files.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.staticfiles</span></code></a>, δείτε στο άρθρο <a class=\"reference internal\" href=\"/el/4.1/howto/static-files/\"><span class=\"doc\">Διαχειρίζοντας τα static files (πχ εικόνες, JavaScript, CSS κλπ)</span></a>.</p>\n</aside>\n<section id=\"serving-static-files-in-production\">\n<span id=\"staticfiles-production\"></span><h2>Εξυπηρετώντας τα static files στην παραγωγή<a class=\"heading-anchor\" href=\"#serving-static-files-in-production\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The basic outline of putting static files into production consists of two\nsteps: run the <a class=\"reference internal\" href=\"/el/4.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> command when static files change, then\narrange for the collected static files directory (<a class=\"reference internal\" href=\"/el/4.1/ref/settings/#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a>) to be\nmoved to the static file server and served. Depending on\n<a class=\"reference internal\" href=\"/el/4.1/ref/settings/#std-setting-STATICFILES_STORAGE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATICFILES_STORAGE</span></code></a>, files may need to be moved to a new location\nmanually or the <a class=\"reference internal\" href=\"/el/4.1/ref/contrib/staticfiles/#django.contrib.staticfiles.storage.StaticFilesStorage.post_process\" title=\"django.contrib.staticfiles.storage.StaticFilesStorage.post_process\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">post_process</span></code></a> method of\nthe <code class=\"docutils literal notranslate\"><span class=\"pre\">Storage</span></code> class might take care of that.</p>\n<p>As with all deployment tasks, the devil’s in the details. Every production\nsetup will be a bit different, so you’ll need to adapt the basic outline to fit\nyour needs. Below are a few common patterns that might help.</p>\n<section id=\"serving-the-site-and-your-static-files-from-the-same-server\">\n<h3>Εξυπηρετώντας το site και τα static files σας από τον ίδιο server<a class=\"heading-anchor\" href=\"#serving-the-site-and-your-static-files-from-the-same-server\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Αν θέλετε να εξυπηρετήσετε τα static files σας από τον ίδιο server ο οποίος εξυπηρετεί ήδη το site σας, η διαδικασία θα μοιάζει κάπως έτσι:</p>\n<ul class=\"simple\">\n<li><p>Ανεβάστε τον κώδικα σας στον deployment server.</p></li>\n<li><p>Στον server, τρέξτε την εντολή <a class=\"reference internal\" href=\"/el/4.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> για να αντιγραφτούν όλα τα static files μέσα στο φάκελο <a class=\"reference internal\" href=\"/el/4.1/ref/settings/#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a>.</p></li>\n<li><p>Παραμετροποιήστε τον Web server σας για να εξυπηρετεί τα αρχεία του φακέλου <a class=\"reference internal\" href=\"/el/4.1/ref/settings/#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a> στο URL <a class=\"reference internal\" href=\"/el/4.1/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=\"reference internal\" href=\"/el/4.1/howto/deployment/wsgi/modwsgi/#serving-files\"><span class=\"std std-ref\">πως μπορείτε να το κάνετε αυτό με τον Apache και το mod_wsgi</span></a>.</p></li>\n</ul>\n<p>You’ll probably want to automate this process, especially if you’ve got\nmultiple web servers.</p>\n</section>\n<section id=\"serving-static-files-from-a-dedicated-server\">\n<h3>Εξυπηρετώντας τα static files από έναν dedicated server<a class=\"heading-anchor\" href=\"#serving-static-files-from-a-dedicated-server\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Most larger Django sites use a separate web server – i.e., one that’s not also\nrunning Django – for serving static files. This server often runs a different\ntype of web server – faster but less full-featured. Some common choices are:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference external\" href=\"https://nginx.org/en/\">Nginx</a></p></li>\n<li><p><a class=\"reference external\" href=\"https://httpd.apache.org/\">Μια stripped-down έκδοση του Apache</a></p></li>\n</ul>\n<p>Η παραμετροποίηση αυτών των servers είναι εκτός του πεδίου εφαρμογής του παρόντος άρθρου. Συμβουλευτείτε το εγχειρίδιο καθενός από τους παραπάνω servers για λεπτομέρειες και οδηγίες.</p>\n<p>Εφόσον ο static file server δεν θα τρέχει το Django, θα χρειαστεί να αλλάξετε τη στρατηγική του deployment για να μοιάζει κάπως έτσι:</p>\n<ul class=\"simple\">\n<li><p>Όταν τα static files αλλάζουν, τρέξτε την εντολή <a class=\"reference internal\" href=\"/el/4.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> τοπικά στον υπολογιστή σας.</p></li>\n<li><p>Ανεβάστε τον τοπικό σας φάκελο <a class=\"reference internal\" href=\"/el/4.1/ref/settings/#std-setting-STATIC_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATIC_ROOT</span></code></a> στον static file server μέσα στο φάκελο όπου εξυπηρετείται. Η εντολή <a class=\"reference external\" href=\"https://rsync.samba.org/\">rsync</a> είναι μια κοινή λύση για αυτό το βήμα καθώς δεν αντιγράφει κάθε φορά όλο το φάκελο, παρά μόνο τις αλλαγές που έγιναν.</p></li>\n</ul>\n</section>\n<section id=\"serving-static-files-from-a-cloud-service-or-cdn\">\n<span id=\"staticfiles-from-cdn\"></span><h3>Εξυπηρετώντας τα static files από μια υπηρεσία cloud ή CDN<a class=\"heading-anchor\" href=\"#serving-static-files-from-a-cloud-service-or-cdn\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Another common tactic is to serve static files from a cloud storage provider\nlike Amazon’s S3 and/or a CDN (content delivery network). This lets you\nignore the problems of serving static files and can often make for\nfaster-loading web pages (especially when using a CDN).</p>\n<p>Όταν χρησιμοποιείτε αυτές τις υπηρεσίες, η βασική διαδικασία θα μοιάζει λίγο-πολύ με την παραπάνω, εκτός του ότι αντί να χρησιμοποιείτε την εντολή <code class=\"docutils literal notranslate\"><span class=\"pre\">rsync</span></code> για να μεταφέρετε τα static files στον server, θα χρειαστεί να μεταφέρετε τα static files στον πάροχο αποθήκευσης αρχείων ή στο CDN.</p>\n<p>There’s any number of ways you might do this, but if the provider has an API,\nyou can use a <a class=\"reference internal\" href=\"/el/4.1/howto/custom-file-storage/\"><span class=\"doc\">custom file storage backend</span></a>\nto integrate the CDN with your Django project. If you’ve written or are using a\n3rd party custom storage backend, you can tell <a class=\"reference internal\" href=\"/el/4.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> to use\nit by setting <a class=\"reference internal\" href=\"/el/4.1/ref/settings/#std-setting-STATICFILES_STORAGE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATICFILES_STORAGE</span></code></a> to the storage engine.</p>\n<p>Για παράδειγμα, αν έχετε γράψει ένα σύστημα αποθήκευσης S3 στο αρχείο <code class=\"docutils literal notranslate\"><span class=\"pre\">myproject.storage.S3Storage</span></code>, μπορείτε να το χρησιμοποιήσετε ως εξής:</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=\"n\">STATICFILES_STORAGE</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;myproject.storage.S3Storage&#39;</span>\n</code></pre></div>\n<p>Once that’s done, all you have to do is run <a class=\"reference internal\" href=\"/el/4.1/ref/contrib/staticfiles/#django-admin-collectstatic\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">collectstatic</span></code></a> and your\nstatic files would be pushed through your storage package up to S3. If you\nlater needed to switch to a different storage provider, you may only have to\nchange your <a class=\"reference internal\" href=\"/el/4.1/ref/settings/#std-setting-STATICFILES_STORAGE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">STATICFILES_STORAGE</span></code></a> setting.</p>\n<p>For details on how you’d write one of these backends, see\n<a class=\"reference internal\" href=\"/el/4.1/howto/custom-file-storage/\"><span class=\"doc\">How to write a custom storage class</span></a>. There are 3rd party apps available that\nprovide storage backends for many common file storage APIs. A good starting\npoint is the <a class=\"reference external\" href=\"https://djangopackages.org/grids/g/storage-backends/\">overview at djangopackages.org</a>.</p>\n</section>\n</section>\n<section id=\"learn-more\">\n<h2>Μάθετε περισσότερα<a class=\"heading-anchor\" href=\"#learn-more\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Για πλήρεις λεπτομέρειες πάνω σε όλες τις ρυθμίσεις, εντολές, template tags και άλλα κομμάτια που περιέχονται στο <a class=\"reference internal\" href=\"/el/4.1/ref/contrib/staticfiles/#module-django.contrib.staticfiles\" title=\"django.contrib.staticfiles: An app for handling static files.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.staticfiles</span></code></a>, δείτε στο άρθρο <a class=\"reference internal\" href=\"/el/4.1/ref/contrib/staticfiles/\"><span class=\"doc\">αναφορά στα staticfiles</span></a>.</p>\n</section>","rootId":"how-to-deploy-static-files","toc":[{"title":"Εξυπηρετώντας τα static files στην παραγωγή","anchor":"serving-static-files-in-production","children":[{"title":"Εξυπηρετώντας το site και τα static files σας από τον ίδιο server","anchor":"serving-the-site-and-your-static-files-from-the-same-server","children":[]},{"title":"Εξυπηρετώντας τα static files από έναν dedicated server","anchor":"serving-static-files-from-a-dedicated-server","children":[]},{"title":"Εξυπηρετώντας τα static files από μια υπηρεσία cloud ή CDN","anchor":"serving-static-files-from-a-cloud-service-or-cdn","children":[]}]},{"title":"Μάθετε περισσότερα","anchor":"learn-more","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"Οδηγοί «Πως-να»","url":"/el/4.1/howto/"}],"prev":{"docname":"howto/static-files/index","title":"How to manage static files (e.g. images, JavaScript, CSS)","url":"/el/4.1/howto/static-files/"},"next":{"docname":"howto/windows","title":"Πώς να εγκαταστήσετε το Django στα Windows","url":"/el/4.1/howto/windows/"},"formats":{"html":"/el/4.1/howto/static-files/deployment/","markdown":"/el/4.1/howto/static-files/deployment.md","json":"/el/4.1/howto/static-files/deployment.json"},"source":"https://github.com/django/django/blob/stable/4.1.x/docs/howto/static-files/deployment.txt","official":"https://docs.djangoproject.com/el/4.1/howto/static-files/deployment/","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","1.11","1.10"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}