From 2a519bfedf1c650453cafa84d61cc79e90f892e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 13 Aug 2017 14:36:45 +0100 Subject: [PATCH] Add SCRIPT_NAME to the production-like server --- README.md | 6 ++-- cof/settings/dev.py | 4 +-- provisioning/bootstrap.sh | 5 +-- provisioning/nginx.conf | 67 ++++++++++++++++++--------------------- 4 files changed, 38 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 0e84146b..01f4ead2 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,9 @@ comme en production : on utilise derrière un reverse-proxy nginx. Ce serveur se lance tout seul et est accessible en dehors de la VM à l'url -`localhost:8080`. Toutefois il ne se recharge pas tout seul lorsque le code -change, il faut relancer le worker avec `sudo systemctl restart worker.service` -pour visualiser la dernière version du code. +`localhost:8080/gestion/`. Toutefois il ne se recharge pas tout seul lorsque le +code change, il faut relancer le worker avec `sudo systemctl restart +worker.service` pour visualiser la dernière version du code. ### Installation manuelle diff --git a/cof/settings/dev.py b/cof/settings/dev.py index 01651bba..9c622063 100644 --- a/cof/settings/dev.py +++ b/cof/settings/dev.py @@ -3,10 +3,8 @@ Django development settings for the cof project. The settings that are not listed here are imported from .common """ -import os - from .common import * # NOQA -from .common import BASE_DIR, INSTALLED_APPS, MIDDLEWARE_CLASSES +from .common import INSTALLED_APPS, MIDDLEWARE_CLASSES EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' diff --git a/provisioning/bootstrap.sh b/provisioning/bootstrap.sh index 4505db3f..69bbcf4c 100644 --- a/provisioning/bootstrap.sh +++ b/provisioning/bootstrap.sh @@ -24,8 +24,9 @@ REDIS_PASSWD="dummy" redis-cli CONFIG SET requirepass $REDIS_PASSWD redis-cli -a $REDIS_PASSWD CONFIG REWRITE -# Contenu static -mkdir -p /srv/gestiocof/{media,static} +# Contenu statique +mkdir -p /srv/gestiocof/media +mkdir -p /srv/gestiocof/static chown -R ubuntu:www-data /srv/gestiocof # Nginx diff --git a/provisioning/nginx.conf b/provisioning/nginx.conf index d2f55bd0..015e1712 100644 --- a/provisioning/nginx.conf +++ b/provisioning/nginx.conf @@ -7,45 +7,15 @@ server { listen 80; server_name localhost; + root /srv/gestiocof/; - # All the trafic is routed to Daphne - location / { - # A copy-paste of what we have in production - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header X-SSL-Client-Serial $ssl_client_serial; - proxy_set_header X-SSL-Client-Verify $ssl_client_verify; - proxy_set_header X-SSL-Client-S-DN $ssl_client_s_dn; - - # Reverse-proxy - proxy_pass http://gestiocof; - } - - # Upgrading the connection when handling websockets - location /ws/ { - # A copy-paste of what we have in production - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header X-SSL-Client-Serial $ssl_client_serial; - proxy_set_header X-SSL-Client-Verify $ssl_client_verify; - proxy_set_header X-SSL-Client-S-DN $ssl_client_s_dn; - - # See http://nginx.org/en/docs/http/websocket.html - proxy_buffering off; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - - proxy_pass http://gestiocof; - } + # / → /gestion/ + # /gestion → /gestion/ + rewrite ^/$ /gestion/; + rewrite ^/gestion$ /gestion/; # Static files location /static/ { - root /srv/gestiocof/; access_log off; add_header Cache-Control "public"; expires 7d; @@ -53,9 +23,34 @@ server { # Uploaded media location /media/ { - root /srv/gestiocof/; access_log off; add_header Cache-Control "public"; expires 7d; } + + location /gestion/ { + # A copy-paste of what we have in production + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-SSL-Client-Serial $ssl_client_serial; + proxy_set_header X-SSL-Client-Verify $ssl_client_verify; + proxy_set_header X-SSL-Client-S-DN $ssl_client_s_dn; + proxy_set_header Daphne-Root-Path /gestion; + + location /gestion/ws/ { + # See http://nginx.org/en/docs/http/websocket.html + proxy_buffering off; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + proxy_pass http://gestiocof/ws/; + } + + location /gestion/ { + proxy_pass http://gestiocof; + } + } }