diff --git a/bikeshop_project/bikeshop/urls.py b/bikeshop_project/bikeshop/urls.py index 5a04e02..ee00ab4 100644 --- a/bikeshop_project/bikeshop/urls.py +++ b/bikeshop_project/bikeshop/urls.py @@ -13,9 +13,12 @@ Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ +from django.conf import settings from django.conf.urls import include, url from django.contrib import admin from django.contrib.auth.views import login +from django.contrib.staticfiles.urls import staticfiles_urlpatterns + from core import urls as core_urls from registration import urls as member_urls @@ -25,3 +28,6 @@ urlpatterns = [ url(r'^member/', include(member_urls)), url(r'^admin/', admin.site.urls), ] + +if getattr(settings, 'DEBUG'): + urlpatterns += staticfiles_urlpatterns() diff --git a/provision/group_vars/all b/provision/group_vars/all index 8c7949c..d4c3bf1 100644 --- a/provision/group_vars/all +++ b/provision/group_vars/all @@ -9,6 +9,8 @@ venv: /opt/venv/{{ app_name }}-{{ group_names[0] }} db_name: "{{ app_name }}_development" db_user: "{{ app_name }}" +app_port: 8475 db_user_password: "{{ secret_db_user_password }}" secret_db_user_password: password +app_domain_name: bikeshop.local \ No newline at end of file diff --git a/provision/roles/nginx/templates/development/nginx-site.conf b/provision/roles/nginx/templates/development/nginx-site.conf new file mode 100644 index 0000000..0320774 --- /dev/null +++ b/provision/roles/nginx/templates/development/nginx-site.conf @@ -0,0 +1,33 @@ +server { + listen 80; + server_name www.{{ app_domain_name }}; + # $scheme will get the http protocol + # and 301 is best practice for tablet, phone, desktop and seo + return 301 http://{{ app_domain_name }}$request_uri; +} + +server { + listen 80; + server_name {{ app_domain_name }}; + + # location = /favicon.ico { access_log off; log_not_found off; } + # location /static/ { + # root {{ app_dir }}; + # } + + # location /media/ { + # root {{ app_dir }}; + # } + + location / { + proxy_pass_header Server; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Scheme $scheme; + proxy_connect_timeout 10; + proxy_read_timeout 10; + proxy_pass http://localhost:{{ app_port }}/; + } +} + diff --git a/provision/roles/supervisor/development/supervisor-program.conf b/provision/roles/supervisor/development/supervisor-program.conf new file mode 100644 index 0000000..882d035 --- /dev/null +++ b/provision/roles/supervisor/development/supervisor-program.conf @@ -0,0 +1,10 @@ +[group:{{ app_name }}] +programs=django +[program:django] +command={{ venv }}/bin/gunicorn -b 127.0.0.1:{{ app_port }} --reload {{ app_name }}.wsgi:application +directory={{ app_dir }} +environment=DJANGO_SETTINGS_MODULE="{{ settings_module }}" +autostart=true +autorestart=true +redirect_stderr=true +user=vagrant diff --git a/provision/site.yml b/provision/site.yml index c3806eb..46eee88 100644 --- a/provision/site.yml +++ b/provision/site.yml @@ -7,6 +7,8 @@ - zenoamaro.postgresql - python - database + - supervisor + - nginx - app - name: Deployment tasks @@ -14,5 +16,4 @@ remote_user: root roles: - deploy-code - - supervisor - - nginx + diff --git a/requirements/development.txt b/requirements/development.txt index ed79a47..b570dc0 100644 --- a/requirements/development.txt +++ b/requirements/development.txt @@ -2,3 +2,4 @@ -r testing.txt django-debug-toolbar PyYAML +gunicorn==19.4.5 \ No newline at end of file diff --git a/requirements/production.txt b/requirements/production.txt index a945c48..a3e81b8 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -1,2 +1 @@ -r base.txt -gunicorn==19.4.5