Skip to content

Commit

Permalink
updated prod conf files
Browse files Browse the repository at this point in the history
  • Loading branch information
Nodraak committed Nov 4, 2014
1 parent 9e31264 commit 37840b5
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 59 deletions.
3 changes: 2 additions & 1 deletion iTeam/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @Author: Adrien Chardon
# @Date: 2014-09-02 12:01:06
# @Last Modified by: Adrien Chardon
# @Last Modified time: 2014-11-02 17:17:31
# @Last Modified time: 2014-11-02 21:25:55

# This file is part of iTeam.org.
# Copyright (C) 2014 Adrien Chardon (Nodraak).
Expand Down Expand Up @@ -156,6 +156,7 @@
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.BrokenLinkEmailsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down
6 changes: 3 additions & 3 deletions prod/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* Nginx
* apt-get install
* Conf file :
* `cp prod/nginx.conf /etc/nginx/sites-available/iteam` + maintenance
* `cp prod/nginx-global.conf /etc/nginx/sites-available/iteam-global` + `cp prod/nginx-prod.conf /etc/nginx/sites-available/iteam-prod` + `cp prod/nginx-maintenance.conf /etc/nginx/sites-available/iteam-maintenance`
* `vim /etc/nginx/sites-available/iteam` -> static/ + media/ path
* cp favicon robots.txt + check conf file
* `ln -s /etc/nginx/sites-available/iteam /etc/nginx/sites-enabled/iteam`
* `ln -s /etc/nginx/sites-available/iteam-prod /etc/nginx/sites-enabled/iteam`
* check nginx conf : `nginx -t`
* Gunicorn
* `pip install gunicorn`
Expand Down Expand Up @@ -108,7 +108,7 @@ A lire :
* django cache https://docs.djangoproject.com/en/dev/topics/cache/
* nginx + static + gzip : http://sametmax.com/servir-des-fichiers-statiques-avec-nginx/
* migrate http://www.djangopro.com/2011/01/django-database-migration-tool-south-explained/

* nginx : root vs alias : http://nginx.org/en/docs/http/ngx_http_core_module.html#alias + http://nginx.org/en/docs/http/ngx_http_core_module.html#root


# Django settings : `settings_prod.py`
Expand Down
6 changes: 3 additions & 3 deletions prod/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cd /opt/iteam-env/iteam-site/

# Maintenance mode
sudo rm /etc/nginx/sites-enabled/iteam
sudo ln -s /etc/nginx/sites-available/iteam-maintenance /etc/nginx/sites-enabled/iteam-maintenance
sudo ln -s /etc/nginx/sites-available/iteam-maintenance /etc/nginx/sites-enabled/iteam
sudo service nginx reload

# save database if something fail
Expand Down Expand Up @@ -48,8 +48,8 @@ deactivate
sudo supervisorctl restart iteam

# Exit maintenance mode
sudo rm /etc/nginx/sites-enabled/iteam-maintenance
sudo ln -s /etc/nginx/sites-available/iteam /etc/nginx/sites-enabled/iteam
sudo rm /etc/nginx/sites-enabled/iteam
sudo ln -s /etc/nginx/sites-available/iteam-prod /etc/nginx/sites-enabled/iteam
sudo service nginx reload

# Display current branch and commit
Expand Down
2 changes: 1 addition & 1 deletion prod/gunicorn_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ exec ../bin/gunicorn iTeam.wsgi:application \
--name=iTeam \
--user=$USER \
--group=$GROUP \
--log-level=debug \
--log-level=info \
--log-file=$LOGFILE 2>>$ERRFILE
47 changes: 24 additions & 23 deletions prod/nginx-maintenance.conf
Original file line number Diff line number Diff line change
@@ -1,63 +1,64 @@
#
# si ca chie, ping Speedking @zestedesavoir.com
#


# Redirect www.domain.tld to domain.tld
#server {
# listen 80;
# server_name www.example.com;
# server_name www.iteam.org;
#
# return 301 http://example.com$request_uri;
# return 301 http://iteam.org$request_uri;
#}

server {
listen 80;
server_name beta.iteam.org;

# log
access_log /opt/iteam-env/log/nginx-access.log;
error_log /opt/iteam-env/log/nginx-error.log;


# media and static files

location /static/ {
alias /opt/iteam-env/static/;
root /opt/iteam-env;
expires 1d;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

location /media/ {
alias /opt/iteam-env/media/;
root /opt/iteam-env;
expires 1d;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

# misc
location /favicon.ico {
root /opt/iteam-env/iteam-site/static/images/;
root /opt/iteam-env/static/images;
}

location /robots.txt {
root /opt/iteam-env/iteam-site/static/;
root /opt/iteam-env/static;
}

# bind 503 to maintenance.html
error_page 503 /maintenance.html;

# return 503 for all requests
location / {
return 503;
# Error pages
error_page 500 501 502 503 504 /500.html;
location = /500.html {
root /opt/iteam-env/iteam-site/templates;
}

# serve maintenance.html
# bind 503 to maintenance.html + location of maintenance.html
error_page 503 /maintenance.html;

location /maintenance.html {
root /opt/iteam-env/iteam-site/templates/;
root /opt/iteam-env/iteam-site/templates;
}

################################################################################

# Error pages

error_page 500 501 502 503 504 /500.html;
location = /500.html {
root /opt/iteam-env/iteam-site/templates/;
# serve maintenance.html
location / {
return 503;
}
}

38 changes: 21 additions & 17 deletions prod/nginx.conf → prod/nginx-prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,49 @@ server {
listen 80;
server_name beta.iteam.org;

# log
access_log /opt/iteam-env/log/nginx-access.log;
error_log /opt/iteam-env/log/nginx-error.log;


# media and static files

location /static/ {
alias /opt/iteam-env/static/;
root /opt/iteam-env;
expires 1d;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

location /media/ {
alias /opt/iteam-env/media/;
root /opt/iteam-env;
expires 1d;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

# misc
location /favicon.ico {
root /opt/iteam-env/iteam-site/static/images/;
root /opt/iteam-env/static/images;
}

location /robots.txt {
root /opt/iteam-env/iteam-site/static/;
root /opt/iteam-env/static;
}

# Error pages
error_page 500 501 502 503 504 /500.html;
location = /500.html {
root /opt/iteam-env/iteam-site/templates;
}

# default : redirect to gunicorn (which will redirect to django)
# bind 503 to maintenance.html + location of maintenance.html
error_page 503 /maintenance.html;

location /maintenance.html {
root /opt/iteam-env/iteam-site/templates;
}

################################################################################

# redirect to gunicorn (which will redirect to django)
location / {
client_max_body_size 100M;
proxy_read_timeout 300s;
Expand All @@ -58,13 +71,4 @@ server {

proxy_pass http://localhost:8000/;
}


# Error pages

error_page 500 501 502 503 504 /500.html;
location = /500.html {
root /opt/iteam-env/iteam-site/templates/;
}
}

55 changes: 44 additions & 11 deletions prod/settings_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,28 @@
import os
SITE_ROOT = os.path.realpath(os.path.dirname(os.path.dirname(__file__)))

################################
# Basic and misc
################################

DEBUG = False
TEMPLATE_DEBUG = False
SERVE = False


ALLOWED_HOSTS = ['localhost']

# Make this unique, and don't share it with anybody.
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'z3rte+c4hikqi-csxbs2&j#+5%nwwbe=ki0j957a^i1%k-hs^^'

################################
# Static and media
################################

ADMINS = (('Adrien Chardon', '[email protected]'),)
SERVER_EMAIL = '[email protected]'
EMAIL_HOST = 'mail.mailoo.org'
EMAIL_HOST_USER = '**********'
EMAIL_HOST_PASSWORD = '*********'
EMAIL_PORT = 25


STATIC_ROOT = os.path.join(SITE_ROOT, '..', 'static')
STATIC_ROOT = '/opt/iteam-env/static'
STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(SITE_ROOT, '..', 'media')
MEDIA_ROOT = '/opt/iteam-env/media'
MEDIA_URL = '/media/'

STATICFILES_DIRS = (
Expand All @@ -37,9 +34,45 @@
('images', os.path.join(SITE_ROOT, 'assets', 'images')),
)

################################
# Database
################################

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(SITE_ROOT, 'db.sqlite3'),
}
}

################################
# Email and errors report
################################

EMAIL_HOST = 'mail.mailoo.org'
EMAIL_HOST_USER = '**********'
EMAIL_HOST_PASSWORD = '*********'
EMAIL_PORT = 25

# Email address that error messages come from.
SERVER_EMAIL = '[email protected]'
# Default email address to use for various automated correspondence from the site managers.
DEFAULT_FROM_EMAIL = '[email protected]'

# Subject-line prefix for email messages send with django.core.mail.mail_admins or ...mail_managers.
# Make sure to include the trailing space.
EMAIL_SUBJECT_PREFIX = '[Django] '

# People who get code error notifications.
ADMINS = (('John Doe', '[email protected]'),)
# Not-necessarily-technical managers of the site. They get broken link notifications and other various emails.
MANAGERS = ADMINS

# Whether to send broken-link emails. Deprecated, must be removed in 1.8.
SEND_BROKEN_LINK_EMAILS = False

#IGNORABLE_404_URLS = (
# re.compile(r'^/apple-touch-icon.*\.png$'),
# re.compile(r'^/favicon.ico$'),
# re.compile(r'^/robots.txt$'),
# )

0 comments on commit 37840b5

Please sign in to comment.