Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added confignginx management command

  • Loading branch information...
commit 5130634406032d4b48ad1c2c417dc551439562df 1 parent 108c3a5
@nicferrier nicferrier authored
View
2  AUTHORS
@@ -0,0 +1,2 @@
+seb@woome.com
+nferrier@ferrier.me.uk
View
13 LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) WooMedia Inc.
+All rights reserved.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
3  MANIFEST.in
@@ -0,0 +1,3 @@
+include AUTHORS
+include LICENSE
+include README
View
8 README
@@ -35,3 +35,11 @@ to the end of the settings.py in the current directory. This is required to be
run once (and once only), and simply adds some import statements to handle
the additional import of per-instance settings files.
+
+confignginx is also included. This is a management command you can use
+to generate Nginx configs from your Django app.
+
+ ./manage.py confignginx --port=8100 --domain=www.example.com
+
+will generare an nginx config that will proxy requests to the port but
+send all static data to the STATIC_ROOT via the STATIC_URL.
View
0  configdir/management/__init__.py
No changes.
View
0  configdir/management/commands/__init__.py
No changes.
View
68 configdir/management/commands/confignginx.py
@@ -0,0 +1,68 @@
+from django.core.management.base import BaseCommand
+from django.core.management.base import CommandError
+from django.conf import settings
+from os.path import abspath
+from optparse import make_option
+
+class Command(BaseCommand):
+ args = ''
+ option_list = BaseCommand.option_list + (
+ make_option(
+ '--port',
+ action='store',
+ dest='tcp_port',
+ default=8099,
+ help='The tcp port to use for Nginx to talk to Django.'
+ ),
+ make_option(
+ '--domain',
+ action='store',
+ dest='domain',
+ help='The fully qualified host name the nginx will host match on'
+ ),
+ )
+
+ help = 'Generates an Nginx config to map the current Django app to Nginx.'
+
+
+ def handle(self, *args, **options):
+ variables = {
+ "HOST_ADDRESS": "127.0.0.1",
+ "PORT": options["tcp_port"],
+ "DOMAIN": options["domain"],
+ "STATIC_URL": settings.STATIC_URL,
+ "DOCROOT": abspath(settings.STATIC_ROOT),
+ }
+ config = """# Nginx config generated by django-config
+
+upstream django {
+ server localhost:%(PORT)s;
+}
+
+server {
+listen %(HOST_ADDRESS)s:80;
+server_name %(DOMAIN)s;
+root %(DOCROOT)s;
+
+location %(STATIC_URL)s {
+ rewrite ^%(STATIC_URL)s(.*)$ /$1 break;
+}
+
+location / {
+ proxy_pass http://django;
+ proxy_redirect off;
+ proxy_set_header Host "%(DOMAIN)s";
+ proxy_next_upstream error timeout;
+ proxy_connect_timeout 120;
+ proxy_send_timeout 120;
+ proxy_read_timeout 120;
+}
+
+}
+""" % variables
+ print config
+
+# End
+
+
+
View
4 setup.py
@@ -10,7 +10,7 @@ def read(fname):
setup(
name = "django_configdir",
- version = "0.1.6",
+ version = "0.1.7",
author = "Seb Potter",
author_email = "seb@woome.com",
description = ("A utility to create per-user, per-host configuration "
@@ -18,7 +18,7 @@ def read(fname):
license = "GPLv2",
keywords = "django configuration instance utility user",
url = "http://github.com/woome/django_configdir",
- packages=['configdir'],
+ packages=['configdir', 'configdir.management', 'configdir.management.commands'],
requires=['django'],
entry_points = {
'console_scripts': [

0 comments on commit 5130634

Please sign in to comment.
Something went wrong with that request. Please try again.