python - 如何在 Ubuntu 14.04 中通过 Apache 网络服务器运行两个 django 项目?

标签 python django apache ubuntu

我能够通过 Apache 服务器运行一个 django 项目。
我有两个项目:yota_admin_module 和 yotasite。
我的 Apache 配置文件:/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

Alias /static /home/abhay/django-project/yota_admin_module/yota/static/
WSGIDaemonProcess yota_admin_module python-path=/home/abhay/django-project/yota_admin_module:/usr/local/lib/python2.7/site-packages
WSGIProcessGroup yota_admin_module
WSGIScriptAlias / /home/abhay/django-project/yota_admin_module/yota_admin_module/wsgi.py

<Directory /home/abhay/django-project/yota_admin_module/ >
       Require all granted
</Directory>

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

但是现在我在尝试使用该 Apache 服务器运行另一个 django 项目时遇到了问题。
所以,我做了什么:在/etc/apache2/sites-available/000-default.conf
以这种方式修改:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

Alias /static /home/abhay/django-project/yota_admin_module/yota/static/
WSGIDaemonProcess yota_admin_module python-path=/home/abhay/django-project/yota_admin_module:/usr/local/lib/python2.7/site-packages
WSGIProcessGroup yota_admin_module
WSGIScriptAlias / /home/abhay/django-project/yota_admin_module/yota_admin_module/wsgi.py

<Directory /home/abhay/django-project/yota_admin_module/ >
       Require all granted
</Directory>

WSGIDaemonProcess yotasite python-path=/home/abhay/django-project/yotasite:/usr/local/lib/python2.7/site-packages
WSGIProcessGroup yotasite
WSGIScriptAlias / /home/abhay/django-project/yotasite/yotasite/wsgi.py

<Directory /home/abhay/django-project/yotasite/ >
       Require all granted
</Directory>


# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

因此,当“sudo service apache2 restart”出现错误时修改后:
[Tue Aug 25 13:21:20.325955 2015] [mpm_event:notice] [pid 4761:tid 140704687433600] AH00491: caught SIGTERM, shutting down
[Tue Aug 25 13:21:21.491426 2015] [mpm_event:notice] [pid 4895:tid 140635456407424] AH00489: Apache/2.4.12 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Tue Aug 25 13:21:21.491930 2015] [core:notice] [pid 4895:tid 140635456407424]  AH00094: Command line: '/usr/sbin/apache2'
[Tue Aug 25 13:21:34.751733 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198] mod_wsgi (pid=4899): Target WSGI script '/home/abhay/django-project/yota_admin_module/yota_admin_module/wsgi.py' cannot be loaded as Python module.
[Tue Aug 25 13:21:34.752015 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198] mod_wsgi (pid=4899): Exception occurred processing WSGI script '/home/abhay/django-project/yota_admin_module/yota_admin_module/wsgi.py'.
[Tue Aug 25 13:21:34.752198 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198] Traceback (most recent call last):
[Tue Aug 25 13:21:34.752358 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198]   File "/home/abhay/django-project/yota_admin_module/yota_admin_module/wsgi.py", line 17, in <module>
[Tue Aug 25 13:21:34.752715 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198]     application = get_wsgi_application()
[Tue Aug 25 13:21:34.752865 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198]   File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Tue Aug 25 13:21:34.753125 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198] django.setup()
[Tue Aug 25 13:21:34.753255 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198]   File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 17, in setup
[Tue Aug 25 13:21:34.753513 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Tue Aug 25 13:21:34.753654 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 48, in __getattr__
[Tue Aug 25 13:21:34.754139 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198] self._setup(name)
[Tue Aug 25 13:21:34.754294 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 44, in _setup
[Tue Aug 25 13:21:34.754445 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198]     self._wrapped = Settings(settings_module)
[Tue Aug 25 13:21:34.754557 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 92, in __init__
[Tue Aug 25 13:21:34.754693 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Tue Aug 25 13:21:34.754800 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198]   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Tue Aug 25 13:21:34.755095 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198] __import__(name)
[Tue Aug 25 13:21:34.755256 2015] [:error] [pid 4899:tid 140635300349696] [remote 127.0.0.1:27198] ImportError: No module named settings

所以,我需要一些指导来解决这个问题,以便使用 Apache 服务器运行两个 django 项目。

最佳答案

各种事情不对劲。请参阅下面的评论。

# Best to match trailing slashes on both arguments to be safe. If
# leave one off on one, can't remember which, the final filesystem
# path will not be formed correctly. Use have trailing slash on both
# or not on either.

Alias /static/ /home/abhay/django-project/yota_admin_module/yota/static/

# If you are needing to include /usr/local/lib/python2.7/site-packages then
# you must be doing something wrong. That should be included by default.
# If it is required, then your mod_wsgi is not compiled for that Python
# installation.

WSGIDaemonProcess yota_admin_module python-path=/home/abhay/django-project/yota_admin_module:/usr/local/lib/python2.7/site-packages

# You can't use WSGIProcessGroup unless you scoped it by a Directory
# of Location directive so it knows which Django instance it applied to.
# Better to use process-group option to WSGIScriptAlias instead so it
# knows for sure. Also force main interpreter context using
# application-group with value of %{GLOBAL}

WSGIScriptAlias / /home/abhay/django-project/yota_admin_module/yota_admin_module/wsgi.py \
    process-group=yota_admin_module application-group=%{GLOBAL}

<Directory /home/abhay/django-project/yota_admin_module/ >
       Require all granted
</Directory>

WSGIDaemonProcess yotasite python-path=/home/abhay/django-project/yotasite:/usr/local/lib/python2.7/site-packages

# You can't have both sites mounted at the root of the host. This second
# one will always be hidden by the first and never get any requests.
# If wanting to have both under same server name, you would need to have
# one at a sub URL. That for a sub URL must be first. That is before
# that for the root of the site.

WSGIScriptAlias / /home/abhay/django-project/yotasite/yotasite/wsgi.py \
    process-group=yotasite application-group=%{GLOBAL}

<Directory /home/abhay/django-project/yotasite/ >
       Require all granted
</Directory>

关于python - 如何在 Ubuntu 14.04 中通过 Apache 网络服务器运行两个 django 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32198477/

相关文章:

django - Geodjango 在 map 上查看管理 ListView

python - Django,在渲染模板之前执行templatetag

python - 如何使用python-docx增加word文档中的段落对象?

python - 将逗号转换为列表中的空格

jquery - 为什么 jQuery ajax jsonp 请求给出错误?

apache - 在 Apache 中设置多个 cookie

java - JAVA中有没有类似XML Beans for 834文件的工具

python - 在 Python 中创建稀疏词矩阵(词袋)

python - 使用 csv.DictReader 读取时如何处理具有重复字段名的 csv 文件?

apache - 使用 rsync 远程 SSH 用户没有外壳访问