在Apache2中部署多个django项目

  1. 将django项目上传到var/www/目录下并修改如下相关文件:

ports.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

NameVirtualHost *:80
Listen 80

NameVirtualHost *:81
Listen 81

<IfModule ssl_module>
	Listen 443
</IfModule>

<IfModule mod_gnutls.c>
	Listen 443
</IfModule>



# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

  1. 在sites-available新增如下文件:
    QX.conf
<VirtualHost *:81>
	ServerName qianxunit.com
	ServerAdmin weimin.he@qianxunit.com
	WSGIScriptAlias / /var/www/QXTechnology/QXTechnology/wsgi.py
	Alias /media/ /var/www/QXTechnology/media/
	Alias /static/ /var/www/QXTechnology/static/
	
	<Directory /var/www/QXTechnology/media>
		Require all granted
	</Directory>

    <Directory /var/www/QXTechnology>
		Require all granted
	</Directory>

	<Directory /var/www/QXTechnology/static>
		Require all granted
	</Directory>
 
 	<Directory /var/www/QXTechnology/QXTechnology>
		<Files wsgi.py>
			Require all granted
		</Files>
	</Directory>
	
	ErrorLog ${APACHE_LOG_DIR}/error.log 
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

原来部署一个项目时的的文件为:
Assets_Management_System.conf

<VirtualHost *:80>
	ServerName marelli.com
	ServerAdmin weimin.he@marelli.com
	WSGIScriptAlias / /var/www/Assets_Management_System/Assets_Management_System/wsgi.py
    Alias /media/ /var/www/Assets_Management_System/media/
    Alias /static/ /var/www/Assets_Management_System/static/
	<Directory /var/www/Assets_Management_System/media>
		Require all granted
	</Directory>

    <Directory /var/www/Assets_Management_System>
		Require all granted
	</Directory>

	<Directory /var/www/Assets_Management_System/static>
		Require all granted
	</Directory>
 
 	<Directory /var/www/Assets_Management_System/Assets_Management_System>
		<Files wsgi.py>
			Require all granted
		</Files>
	</Directory>
	
	ErrorLog ${APACHE_LOG_DIR}/error.log 
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

  1. 最后再重启下服务器即可

注意:
wsgi文件:

# -*- coding: utf-8 -*-

# import logging
# import os

# from django.core.wsgi import get_wsgi_application


# logging.captureWarnings(True)
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "QXTechnology.settings.dev")

# application = get_wsgi_application()


import logging
import os
import sys
sys.path.append('/var/www/QXTechnology')

from django.core.wsgi import get_wsgi_application


logging.captureWarnings(True)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "QXTechnology.settings.dev")

application = get_wsgi_application()
"""
WSGI config for Assets_Management_System project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""

import os, sys, logging

from django.core.wsgi import get_wsgi_application

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)

logging.captureWarnings(True)

os.environ['DJANGO_SETTINGS_MODULE'] = 'Assets_Management_System.settings'
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Assets_Management_System.settings')

application = get_wsgi_application()
上一篇:Depends: apache2-bin (= 2.4.29-1ubuntu4.14) but 2.4.29-1ubuntu4.15 is to be installed


下一篇:Android View的绘制流程