Apache: industrial-strength Web Server
Preparing Your Codebase for Production
1. settings.py
DEBUG = False
TEMPLATE_DEBUG = False
2. root template directory
404.html
500.html
(not rely on other templates)
unhandled Python exception
Need Email Set up
http://www.djangobook.com/en/2.0/chapter12.html
Using Multiple settings.py for Development and Production
Three ways:
- Two independent settings files
- base setting file and inherited setting file
- one single setting.py with Python logic to change the settings based on context
1. Copy as settings.py settings_production.py
2. IMPORT
override
3. use of Python logic
IF the name of settings changed:
You can fix this by editing manage.py to change settingsto the name of your module
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "quality.settings_XXX")
Apache + mod_python
Basic Configuration
make sure you have Apache installed with the mod_python module activated.
Make sure to replace mysite.settings with the appropriate DJANGO_SETTINGS_MODULE for your site.
This tells Apache, “Use mod_python for any URL at or under ‘/’, using the Django mod_python handler.” It passes the value of DJANGO_SETTINGS_MODULE so mod_python knows which settings to use.
Note that we’re using the <Location> directive, not the <Directory> directive. The latter is used for pointing at places on your filesystem, whereas <Location> points at places in the URL structure of a Web site. <Directory> would be meaningless here.
Apache likely runs as a different user than your normal login and may have a different path and sys.path. You may need to tell mod_python how to find your project and Django itself.
Running Multiple Django Installations on the Same Apache Instance
to be continued
Running a Development Server with mod_python
Serving Django and Media Files from the Same Apache Instance
Alternative:
Using Django with FastCGI
http://www.djangobook.com/en/2.0/chapter12.html
Scaling
Figure 12-1: a single server Django setup.
However, as traffic increases you’ll quickly run into resource contention between the different pieces of software.
Figure 12-2: Moving the database onto a dedicated server
As far as Django is concerned, the process of separating out the database server is extremely easy: you’ll simply need to change the DATABASE_HOST setting to the IP or DNS name of your database server. It’s probably a good idea to use the IP if at all possible, as relying on DNS for the connection between your Web server and database server isn’t recommended.
Figure 12-3: Separating out the media server.
For sites heavy in static content (photos, videos, etc.), moving to a separate media server is doubly important. Three-server setup: 10 million hits a day
Figure 12-4: A load-balanced, redundant server setup.
Figure 12-5. An example large-scale Django setup.
Performance Tuning
There’s No Such Thing As Too Much RAM
This shouldn’t be too hard; we’ve developed a site with more than half a million newspaper articles, and it took under 2GB of space.Turn Off Keep-Alive
Use memcached
done
done
No comments:
Post a Comment