• Digital accessories
  • Server
  • Digital life
  • Privacy policy
  • Contact us
  1. Home
  2. Article
  3. Apache2 Virtual Host Configuration — django-project-skeleton ...

Apache2 Virtual Host Configuration — django-project-skeleton ...

Rsdaa 24/10/2021 1753

Apache2 Virtual Host Configuration

This is an Apache2 configuration file for name based virtual hosting.

As you can see in the following listing, there are several placeholders,that must be filled to make this work.

Usage

As you may notice, there are three different types of placeholders.

[[placeholder_name]]

These placeholders must be filled manually. Most noticable is line 4,where you must set the server name.

ServerName[[SERVER_NAME]]

${placeholder_name}These placeholders are filled by Apache itsself. Only mess with them, ifyou do exactly know what you are doing.{{ placeholder_name }}

These placeholders do look familiar, don’t they? These are Djangotemplatetags. You may fill them manually (please refer to the providedresources in the comments), but you can Django let them fill them for youduring project creation. This will render the file through Django’stemplate engine and fill these placeholders:

$ django-admin startproject --template=/path/to/template --name apache2_vhost.sample

Concept

This will set up a name based virtual host that uses mod_wsgi to interactwith Django.

It will serve static- and media-files from the default locations set insettings/common.py. This is not a production-setting, but is well suitedfor development purposes.

Line 10: Alias /static/ {{ project_directory }}/run/staticServe static files from STATIC_ROOT under STATIC_URL. Note lines36 - 40, where the directory is made accessible for Apache.Line 15: Alias /media/{{ project_directory }}/run/mediaServe media files from MEDIA_ROOT under MEDIA_URL. Note lines45 - 49, where the directory is made accessible for Apache.

The dynamic Django content is served using the WSGI-application. Apache2 willuse mod_wsgi in Daemon-mode. This is in fact the preferred way of deployingDjango with Apache2, so you will not have to mess with these settings.

Line 18: WSGIScriptAlias/ {{ project_directory }}/{{ project_name }}/wsgi.pyThis must be set to the absolute filesystem path to the WSGI-application.Line 27: WSGIDaemonProcess ...This sets the name of the daemon process. Using Django’s template engine,this will be set to the name of your project. Please notice thepython-path-parameter. It is prepared to a virtualenv-setup, butfrankly, it must contain the project directory and the path to Python’ssite-packages.Line 31: WSGIProcessGroup ...Specifies a distinct name for the daemon process’s group.

Source

1 2 3 4 5 6 7 8 91011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
*:80># This is name based virtual hosting. So place an appropriate server name# here. Example: django.devsrv.localServerName[[SERVER_NAME]]ServerAdmin webmaster@localhost# This alias makes serving static files possible.# Please note, that this is geared to our settings/common.py# In production environment, you will propably adjust this!Alias /static/{{ project_directory }}/run/static/# This alias makes serving media files possible.# Please note, that this is geared to our settings/common.py# In production environment, you will propably adjust this!Alias /media/{{ project_directory }}/run/media/# Insert the full path to the wsgi.py-file hereWSGIScriptAlias / {{ project_directory }}/{{ project_name }}/wsgi.py# PROCESS_NAME specifies a distinct name of this process# see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess# PATH/TO/PROJECT_ROOT is the full path to your project's root directory, # containing your project files# PATH/TO/VIRTUALENV/ROOT: If you are using a virtualenv specify the full# path to its directory.# Generally you must specify the path to Python's site-packages.WSGIDaemonProcess {{ project_name }}python-path={{ project_directory }}:{{ project_directory }}/../lib/python2.7/site-packages# PROCESS_GROUP specifies a distinct name for the process group# see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIProcessGroupWSGIProcessGroup{{ project_name }}# Serving static files from this directory# Please note, that this is geared to our settings/common.py# In production environment, you will propably adjust this! {{ project_directory }}/run/static>Options -IndexesOrder deny,allowAllow from all# Serving media files from this directory# Please note, that this is geared to our settings/common.py# In production environment, you will propably adjust this! {{ project_directory }}/run/media>Options -IndexesOrder deny,allowAllow from allLogLevel warn# PROJECT_NAME is used to seperate the log files of this applicationErrorLog${APACHE_LOG_DIR}/{{ project_name }}_error.logCustomLog ${APACHE_LOG_DIR}/{{ project_name }}_access.log combined

PREV: A dns server cannot be used ps4;Problems playing online with ...

NEXT: DNS Server Not Responding PS4 Fix - Actionable Solution (2021)

Popular Articles

Hot Articles

Navigation Lists

Back to Top