0

I am able to run one django project through Apache server. I have two projects: yota_admin_module and yotasite. My Apache conf file: /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

But now I am facing problem when trying to run another django project with that Apache server. So, what I did: inside /etc/apache2/sites-available/000-default.conf modified in this way:

<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

So, after modifying this when "sudo service apache2 restart" is given getting error:

[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

So, I need some guidance to fix this to run two django projects with Apache server.

1 Answer 1

1

Various things wrong. See comments below.

# 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>
Sign up to request clarification or add additional context in comments.

2 Comments

-> thanks for your guide. One more thing would you please explain : # 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. and how to implement. I want both sites to be running through Apache.
You would have to have them as different host names, which means you would have to have multiple VirtualHost with one in each. You then need separate hosts names under your control which can be used to map to them. Otherwise you use separate ports, with different VirtualHost, or put one under a sub URL. You can't have both trying to accept requests for the same host name at root of the site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.