From 2ba1fe2a0f9a93ecb5c89e56fed8aab4590cd0ba Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Thu, 28 Sep 2017 09:35:05 +0200 Subject: [PATCH] Instructions for using Nginx in big mode --- CHANGELOG | 3 +-- DEVELOPMENT.rst | 56 +++++++++++++++++++++++++++++++++++++-- openslides/core/views.py | 6 ++--- openslides/utils/views.py | 4 +-- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 920e812cb..ab671637a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -85,8 +85,7 @@ Core: - Added custom translations in config [#3383]. - Added dynamic webpage title [#3404]. - Added 'go to top'-link [#3404]. -- Added caching for the index views. When using a Webserver for serving - static files see the example configuration in the PR [#3419]. +- Added caching for the index views [#3419]. - Added projector prioritization [#3425]. Mediafiles: diff --git a/DEVELOPMENT.rst b/DEVELOPMENT.rst index 04eab3965..c702ed1fb 100644 --- a/DEVELOPMENT.rst +++ b/DEVELOPMENT.rst @@ -193,9 +193,12 @@ Populate your new database:: 4. Run OpenSlides ----------------- -First start e. g. four workers:: +First start e. g. four workers (do not use the `--threads` option, because the threads will not spawn across all cores):: - $ python manage.py runworker --threads 4 + $ python manage.py runworker& + $ python manage.py runworker& + $ python manage.py runworker& + $ python manage.py runworker& To start Daphne as protocol server run:: @@ -207,3 +210,52 @@ To use Geiss instead of Daphne, just download Geiss and start it:: $ python manage.py getgeiss $ ./personal_data/var/geiss + +5. Use Nginx (optional) + +When using Nginx as a proxy for delivering staticfiles the performance of the setup will increase very much. For delivering staticfiles you have to collect those:: + + $ python manage.py collectstatic + +This is an example configuration for a single Daphne/Geiss listen on port 8000:: + + server { + listen 80; + listen [::]:80; + + server_name _; + + location /static { + alias /collected-static; + } + location ~* ^/(?!ws|wss|webclient|core/servertime|users/whoami|users/login|users/logout|users/setpassword|motions/docxtemplate|projector|real-projector|static|media|rest).*$ { + rewrite ^.*$ /static/html/index.html; + } + location ~* ^/projector.*$ { + rewrite ^.*$ /static/html/projector-container.html; + } + location ~* ^/real-projector.*$ { + rewrite ^.*$ /static/html/projector.html; + } + location ~* ^/webclient.*$ { + rewrite ^/webclient/(site|projector).*$ /static/js/webclient-$1.js; + } + + location / { + proxy_pass http://localhost:8000; + proxy_read_timeout 5m; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Scheme $scheme; + } + } + +Using Nginx as a load balancer is fairly easy. Just start multiple Daphnes/Geiss on different ports, change the `proxy_pass` to `http://openslides/` and add this on top of the Nginx configuration:: + + upstream openslides { + server localhost:2001; + server localhost:2002; + } diff --git a/openslides/core/views.py b/openslides/core/views.py index dc8ee47f7..d29b0cef4 100644 --- a/openslides/core/views.py +++ b/openslides/core/views.py @@ -53,7 +53,7 @@ from .models import ( # Special Django views -class IndexView(utils_views.CSRFMixin, utils_views.IndexView): +class IndexView(utils_views.CSRFMixin, utils_views.TemplateView): """ The primary view for OpenSlides using AngularJS. @@ -64,7 +64,7 @@ class IndexView(utils_views.CSRFMixin, utils_views.IndexView): template_name = 'templates/index.html' -class ProjectorView(utils_views.IndexView): +class ProjectorView(utils_views.TemplateView): """ The primary view for OpenSlides projector using AngularJS. @@ -74,7 +74,7 @@ class ProjectorView(utils_views.IndexView): template_name = 'templates/projector-container.html' -class RealProjectorView(utils_views.IndexView): +class RealProjectorView(utils_views.TemplateView): """ The original view without resolutioncontrol for OpenSlides projector using AngularJS. diff --git a/openslides/utils/views.py b/openslides/utils/views.py index a479d8c75..c92f40d2b 100644 --- a/openslides/utils/views.py +++ b/openslides/utils/views.py @@ -50,9 +50,9 @@ class APIView(_APIView): del method_call -class IndexView(View): +class TemplateView(View): """ - A view to serve a single cached template file. Subclasses has to provide 'template_name'. + A view to serve a single cached template file. Subclasses have to provide 'template_name'. """ template_name = None # type: str