we are trying to run django3 (python3.6 on Centos7) with httpd.
i get following error when i run it by HTTPD.
[Tue Jan 12 06:52:04.575618 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] Traceback (most recent call last):
[Tue Jan 12 06:52:04.575665 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/srv/django/django/wsgi.py", line 16, in <module>
[Tue Jan 12 06:52:04.575670 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] application=get_wsgi_application()
[Tue Jan 12 06:52:04.575678 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/local/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Tue Jan 12 06:52:04.575682 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] django.setup(set_prefix=False)
[Tue Jan 12 06:52:04.575690 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
[Tue Jan 12 06:52:04.575694 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Tue Jan 12 06:52:04.575701 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 82, in __getattr__
[Tue Jan 12 06:52:04.575706 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] self._setup(name)
[Tue Jan 12 06:52:04.575713 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 69, in _setup
[Tue Jan 12 06:52:04.575717 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] self._wrapped = Settings(settings_module)
[Tue Jan 12 06:52:04.575724 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 170, in __init__
[Tue Jan 12 06:52:04.575729 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] mod = importlib.import_module(self.SETTINGS_MODULE)
[Tue Jan 12 06:52:04.575736 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
[Tue Jan 12 06:52:04.575740 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] return _bootstrap._gcd_import(name[level:], package, level)
[Tue Jan 12 06:52:04.575747 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Tue Jan 12 06:52:04.575755 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Tue Jan 12 06:52:04.575762 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Tue Jan 12 06:52:04.575780 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] ModuleNotFoundError: No module named 'django.settings'```
my django.conf file in /etc/httpd/conf.d is as follows:
Alias /static /srv/static
<Directory /srv/static>
Require all granted
</Directory>
<Directory /srv/django/django>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess django python-path=/srv/django:/usr/local/lib/python3.6/site-packages
WSGIProcessGroup django
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /srv/django/django/wsgi.py
and my wsgi.py as as follows:
import os
import sys
from django.core.wsgi import get_wsgi_application
os.chdir('/srv/django/')
sys.path.append('/srv/django/')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django.settings')
application=get_wsgi_application()
we installed following packages
python3-devel.x86_64
rh-python36-mod_wsgi.x86_64
yum install httpd-devel
django project as such is working fine
100.10.100.10 (/srv/django/)-1003> python3 manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
January 12, 2021 - 05:22:31
Django version 3.1.5, using settings 'django.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
what am i missing?
I am not too familiar on how well Apache Httpd works with WSGI, but if you're starting Django separately and you simply want to a reverse proxy up an running quickly you could do the following:
<VirtualHost *:80>
ServerAdmin admin#localhost
ProxyRequests off
DocumentRoot /var/www
# SSLProxyEngine on
# ProxyPreserveHost On
ServerName www.yoursite.net
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel error
<Location />
ProxyPass http://www.yourwebsite.net/
ProxyPassReverse http://localhost:8080/
Order allow,deny
Allow from all
</Location>
</VirtualHost>
In terms of the error, it looks like wsgi.py can't find django.settings meaning the django directory and settings module aren't in the current path.
Related
I have been pulling my hair out with this and I dont know what else I should do.
For context, I am trying to host 2 django websites on the same Apache2 server. I am able to setup 1 website with ease but whenever I try to add a second one everything breaks.
At the momento both webs are located in in /home/my_usr dir.
So we would have /home/my_usr/web1 and /home/my_usr/web2.
My web1-web2.conf file looks like:
WSGIDaemonProcess web1 python-home=/home/my_usr/web1/env python-path=/home/my_usr/web1
WSGIProcessGroup web1
WSGIDaemonProcess web2 python-home=/home/my_usr/web2/env python-path=/home/my_usr/web2
WSGIProcessGroup web2
<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
ServerAdmin webmaster#localhost
# 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
Alias /web1/static /home/my_usr/web1/static
<Directory /home/my_usr/web1/static>
Require all granted
</Directory>
Alias /media /home/my_usr/web1/media
<Directory /home/my_usr/web1/media>
Require all granted
</Directory>
<Directory /home/my_usr/web1/web1>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias /web1 /home/my_usr/web1/web1/wsgi.py
Alias /web2/static/ /home/my_usr/web2/static
<Directory /home/my_usr/web2/static>
Require all granted
</Directory>
Alias /media /home/my_usr/web2/media
<Directory /home/my_usr/web2/media>
Require all granted
</Directory>
<Directory /home/my_usr/web2//web>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias /web2 /home/my_usr/web2/web2/wsgi.py
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
With this conf file, and right after I execute sudo service apache2 restart, if I go onto host/web1 web1 works perfeclty fine but if I want to access to host/web2 I get an error message and this error in the error.log file:
[Fri Jul 02 11:45:45.210666 2021] [mpm_prefork:notice] [pid 29254] AH00163: Apache/2.4.46 (Debian) mod_wsgi/4.6.5 Python/3.7 configured -- resuming normal operations
[Fri Jul 02 11:45:45.210780 2021] [core:notice] [pid 29254] AH00094: Command line: '/usr/sbin/apache2'
[Fri Jul 02 11:46:13.416556 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] mod_wsgi (pid=29256): Failed to exec Python script file '/home/my_usr/web2/web2/wsgi.py'.
[Fri Jul 02 11:46:13.416650 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] mod_wsgi (pid=29256): Exception occurred processing WSGI script '/home/my_usr/web2/web2/wsgi.py'.
[Fri Jul 02 11:46:13.417397 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] Traceback (most recent call last):
[Fri Jul 02 11:46:13.417464 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/web2/wsgi.py", line 24, in <module>
[Fri Jul 02 11:46:13.417517 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] application = get_wsgi_application()
[Fri Jul 02 11:46:13.417526 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/env/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Fri Jul 02 11:46:13.417530 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] django.setup(set_prefix=False)
[Fri Jul 02 11:46:13.417546 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/env/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
[Fri Jul 02 11:46:13.417550 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Fri Jul 02 11:46:13.417555 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/env/lib/python3.7/site-packages/django/conf/__init__.py", line 82, in __getattr__
[Fri Jul 02 11:46:13.417559 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] self._setup(name)
[Fri Jul 02 11:46:13.417564 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/env/lib/python3.7/site-packages/django/conf/__init__.py", line 69, in _setup
[Fri Jul 02 11:46:13.417567 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] self._wrapped = Settings(settings_module)
[Fri Jul 02 11:46:13.417572 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/home/my_usr/web2/env/lib/python3.7/site-packages/django/conf/__init__.py", line 170, in __init__
[Fri Jul 02 11:46:13.417575 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] mod = importlib.import_module(self.SETTINGS_MODULE)
[Fri Jul 02 11:46:13.417580 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
[Fri Jul 02 11:46:13.417583 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] return _bootstrap._gcd_import(name[level:], package, level)
[Fri Jul 02 11:46:13.417588 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
[Fri Jul 02 11:46:13.417593 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 983, in _find_and_load
[Fri Jul 02 11:46:13.417598 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Fri Jul 02 11:46:13.417603 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Fri Jul 02 11:46:13.417608 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
[Fri Jul 02 11:46:13.417612 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 983, in _find_and_load
[Fri Jul 02 11:46:13.417617 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
[Fri Jul 02 11:46:13.417634 2021] [wsgi:error] [pid 29256] [remote 192.168.20.32:25195] ModuleNotFoundError: No module named 'web1'
Whereas, if I execute sudo service apache2 restart and directly go onto host/web2 now web2 works perfectly fine but if after that I try to go onto host/web1 it shows web2.
So basically if I restart apache2 service then go to host/web1 and after that host/web2 I get a message error and the logs posted.
If I restart apache2 service then go to host/web2 and after that host/web1 I get web2 contents even though the url is host/web2
Any clue what could be going?
Thanks in advance
Okey I figured it out! Hope this helps someone in the future.
So my .conf file was all good from the headstart what was giving me trouble was the .settings files of my django projects.
Thanks to this article I fixed it.
I had my settings files like this:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
And changed it to:
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
I am getting the following error. I tried the other answers provided for the same error but nothing is working. Any help would be appreciated.
Apache error log:
[Thu Aug 10 19:51:22.397653 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Target WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py' cannot be loaded as Python module.
[Thu Aug 10 19:51:22.397731 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Exception occurred processing WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py'.
[Thu Aug 10 19:51:22.398589 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] Traceback (most recent call last):
[Thu Aug 10 19:51:22.398657 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py", line 16, in <module>
[Thu Aug 10 19:51:22.398664 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] application = get_wsgi_application()
[Thu Aug 10 19:51:22.398675 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu Aug 10 19:51:22.398680 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] django.setup(set_prefix=False)
[Thu Aug 10 19:51:22.398689 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
[Thu Aug 10 19:51:22.398694 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Thu Aug 10 19:51:22.398703 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__
[Thu Aug 10 19:51:22.398708 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] self._setup(name)
[Thu Aug 10 19:51:22.398717 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
[Thu Aug 10 19:51:22.398722 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] self._wrapped = Settings(settings_module)
[Thu Aug 10 19:51:22.398731 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages/django/conf/__init__.py", line 110, in __init__
[Thu Aug 10 19:51:22.398736 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Aug 10 19:51:22.398745 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "/home/sharan/myproject/myprojectenv/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Thu Aug 10 19:51:22.398749 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] return _bootstrap._gcd_import(name[level:], package, level)
[Thu Aug 10 19:51:22.398758 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Thu Aug 10 19:51:22.398776 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Thu Aug 10 19:51:22.398786 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Thu Aug 10 19:51:22.398795 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Thu Aug 10 19:51:22.398864 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Thu Aug 10 19:51:22.398879 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Thu Aug 10 19:51:22.398889 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Thu Aug 10 19:51:22.398913 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] ImportError: No module named 'proj_VivRx1'
Virtualhost file (apache2/sites-available/000-default.conf)
ServerAdmin webmaster#localhost
DocumentRoot /home/sharan/myproject
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/sharan/myproject/proj_VivRx1/app_match/static
<Directory /home/sharan/myproject/proj_VivRx1/app_match/static>
Require all granted
</Directory>
<Directory /home/sharan/myproject/proj_VivRx1/proj_VivRx1>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/sharan/myproject/proj_VivRx1/proj_VivRx1>
Require all granted
</Directory>
<Directory /home/sharan/myproject/proj_VivRx1>
Require all granted
</Directory>
<Directory /home/sharan/myproject/myprojectenv>
Require all granted
</Directory>
WSGIDaemonProcess myproject python-path=/home/sharan/myprojects python-home=/home/sharan/myproject/myprojectenv
WSGIProcessGroup myproject
WSGIScriptAlias / /home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py
WSGI file (/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py):
import os,sys
sys.path.append('/home/sharan/myproject/myprojectenv/lib/python3.5/site-packages')
sys.path.append('/home/sharan/myproject/proj_VivRx1')
from django.core.wsgi import get_wsgi_application
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:
sys.path.append(path)
os.environ["DJANGO_SETTINGS_MODULE"] = "{{ project_name }}.settings"
application = get_wsgi_application()
I have tried playing around with locations. Also checked the permissions but to no use. Apache version is 2.4.18.
You should add your project path (/home/sharan/myproject/proj_VivRx1) to python-path parameter of WSGIDaemonProcess Apache directive.
*
[Thu Aug 10 19:51:22.397653 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Target WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py' cannot be loaded as Python module.
[Thu Aug 10 19:51:22.397731 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] mod_wsgi (pid=10908): Exception occurred processing WSGI script '/home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py'.
[Thu Aug 10 19:51:22.398589 2017] [wsgi:error] [pid 10908:tid 3048807232] [remote 10.0.2.15:12215] Traceback (most recent call last):
Your directory structure is messed up. You have a mixmatch of directories where your wsgi file is located, is it in /home/sharan/myproject/proj_VivRx1/proj_VivRx1/wsgi.py as the virtual host is setup to look for it... or is it /home/sharan/myproject/proj_VivRx1/wsgi.py?
You most likely need to adjust your folder paths to point to the right location where your wsgi file is located.
I am struggling trying to get Apache 2.4.7 to serve a Django 1.8.17 application using mod_wsgi 4.5.15 with Python 3.5.3 as a virtual environment. This is the only virtual environment I have on the machine (Linux Mint 17.3).
I am getting an "internal Server Error" in the browser.
My Apache error log says:
[Thu Apr 06 19:48:22.530935 2017] [mpm_prefork:notice] [pid 4476] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.21 mod_wsgi/4.5.15 Python/3.5 configured -- resuming normal operations
[Thu Apr 06 19:48:22.531008 2017] [core:notice] [pid 4476] AH00094: Command line: '/usr/sbin/apache2'
[Thu Apr 06 19:48:28.165360 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] mod_wsgi (pid=4480): Target WSGI script '/home/magic-rat/ektropy_project/ektropy_project/wsgi.py' cannot be loaded as Python module.
[Thu Apr 06 19:48:28.165494 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] mod_wsgi (pid=4480): Exception occurred processing WSGI script '/home/magic-rat/ektropy_project/ektropy_project/wsgi.py'.
[Thu Apr 06 19:48:28.166150 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] Traceback (most recent call last):
[Thu Apr 06 19:48:28.166210 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/ektropy_project/ektropy_project/wsgi.py", line 16, in <module>
[Thu Apr 06 19:48:28.166218 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] application = get_wsgi_application()
[Thu Apr 06 19:48:28.166230 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Thu Apr 06 19:48:28.166238 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] django.setup()
[Thu Apr 06 19:48:28.166250 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/__init__.py", line 17, in setup
[Thu Apr 06 19:48:28.166257 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Thu Apr 06 19:48:28.166269 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/conf/__init__.py", line 48, in __getattr__
[Thu Apr 06 19:48:28.166276 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] self._setup(name)
[Thu Apr 06 19:48:28.166288 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/conf/__init__.py", line 44, in _setup
[Thu Apr 06 19:48:28.166295 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] self._wrapped = Settings(settings_module)
[Thu Apr 06 19:48:28.166307 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/conf/__init__.py", line 92, in __init__
[Thu Apr 06 19:48:28.166314 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Apr 06 19:48:28.166325 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/usr/local/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Thu Apr 06 19:48:28.166335 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] return _bootstrap._gcd_import(name[level:], package, level)
[Thu Apr 06 19:48:28.166347 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Thu Apr 06 19:48:28.166358 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Thu Apr 06 19:48:28.166369 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Thu Apr 06 19:48:28.166381 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Thu Apr 06 19:48:28.166392 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Thu Apr 06 19:48:28.166418 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Thu Apr 06 19:48:28.166429 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Thu Apr 06 19:48:28.166464 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] ImportError: No module named 'ektropy_project'
My directory structure is:
home/magic-rat/
|
|__________virtualenvs
| |
| |-ektropy_project
| |
| |-lib
| |
| |-python3.5
| |
| |-site_packages
|
|__________ektropy_project
|
|-manage.py
|
|-ektropy_project
|
|-wsgi.py
|-helloworld.wsgi (so you can see where it is)
My Apache Virtual host file is:
<VirtualHost *:8000>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
WSGIDaemonProcess ektropy_project python-home=/home/magic-rat/virtualenvs/ektropy_project
WSGIProcessGroup ektropy_project
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /home/magic-rat/ektropy_project/ektropy_project/wsgi.py
<Directory /home/magic-rat/ektropy_project/ektropy_project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
My wsgi.py file is:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ektropy_project.settings")
application = get_wsgi_application()
I believe mod_wsgi is configured properly. I can run a simple hello_world program and it works.
I believe permissions are set properly on all the files.
Any help is appreciated.
Add an extra option to WSGIDaemonProcess of:
python-path=/home/magic-rat/ektropy_project
You have to tell mod_wsgi where your project code is as well so it can import it.
conclusion of this question
1.what I wanted to do in the first place.
i wanted to allow only some user in Django can upload file. I could do write codes to do that in Django web framework. But if you set upload folder as r__ permssions, you can't upload file in the first place. I just set my upload folder as drwxrwxrwx 777 permssions to let my users in Django can upload files. leaving your folder as 777 permssion seems bad idea for security reason clearly. I wanted to set my media folder as 774 or 764.
My searching apache authentication and mod wsgi started from my wrong understanding. I thought I can allow users in django have owner or group permssion in ubuntu. for example, if you a user in Django are in a group named 'tester', you can access to a folder has 'drwxrwxr__ tester tester'.
and I thought only embedded mode is possible to use apache authentication. But that was my misunderstanding.
in conclusion, I can solve my problem by setting owner and group permission following apache default user or (more secure) user/group you set with options of WSGIDaemonProcess. Then you manage which user can upload files in your media file in Django(I would use PermissionMixin class)
additionally, This is what and how I understood in here.
1) WSGIDaemon mode is recommended in most cases. check Graham Dumpleton's article in here. It seems Embedded mode could be more efficient if you use just simple codes.
2) 'you can expect to see slowdowns once you get above a few hundred entries, and may wish to consider a different authentication method at that time'. This kind of slowdown is caused when using htpasswd file with Apache AuthUserFile. But if you let Django do authentication, it bypass the scanning of a flat file. So It is not a case when you hook Django authentication in mod wsgi.
Down below, I put link how solve when you have an error which is caused by version of mod_wsgi and version of python and explains how I fixed my codes to set embedded mode thanks to #Graham Dumpleton.
Procedure of how I solve my errors when I set embedded mode
First, I didn't have problem to work with daemon mode of mod_wsgi.
I wanted to use embedded mode of mod_wsgi with virtualenv. The reason why I wanted to use embedded mode is to use apache basic or digest authentication with mod_wsgi. according to this, 'By default the auth providers are executed in context of first interpreter created b y Python. ie., '%{GLOBAL}' and always in the Apache child processes, never in a daemon process'. I understood I can use apache basic or digest authentication with only embedded mode of mod_wsgi.
1.error because low version of mod_wsgi
If you install libapache2-mod-wsgi-py3 by apt-get in ubuntu 14 or 16, version of it is 3.4
according to this link, mod_wsgi version 4.2+ is needed for python 3.4. I installed mod_wsgi 4.5.7 following instructions in that link. no more error.
2.error with WSGIPythonPath
I followed instructions in django doc. I kept making an error and I figured out that it doesnt work with virtualenv. I found this article. I thought this is a way to solve my problem but it still doesn't work. I can't understand why it doesn't work and can't find better resource than links I mentioned.
<VirtualHost *:80>
WSGIScriptAlias / /home/cango/myproject/myproject/wsgi.py
WSGIPythonPath home/cango/myvenv/lib/python3.5/site-packages
# I also tried /home/~ I put / at very beginning. It didn't work too.
<Directory /home/cango/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
but if I change little bit to use daemon mode like below, it works!
<VirtualHost *:80>
WSGIDaemonProcess cango python-path=/home/cango/myproject:home/cango/myvenv/lib/Python3.5/site-packages
WSGIProcessGroup cango
WSGIScriptAlias / /home/cango/myproject/myproject/wsgi.py
#WSGIPythonPath home/cango/myvenv/lib/python3.5/site-packages
<Directory /home/cango/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
exactly same except a few lines for Daemon mode.
------------------- when I applied according to comments-------------------
1.Both WSGIPythonPath and WSGIPythonHome shouldn't be inside of a VirtualHost.
I added WSGIPythonPath in wsgi.conf under /etc/apache2/mods-available
wsgi.conf
<IfModule mod_wsgi.c>
WSGIPythonHome /usr/local/pythonenv
#WSGIPythonPath /usr/local/pythonenv/lib/python3.5/site-packages
#From comment, I don't need to add WSGIPythonPath, WSGIPythonHome is enough to set
I remained wsgi.load under /etc/apache2/mode-available same like below
wsgi.load
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so
I removed WSGIPythonPath in VirtualHost setting.
000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /home/cango/myproject/myproject/wsgi.py
<Directory /home/cango/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
now I don't get a error which I had before 'WSGIPythonPath something error'. but when I hit my IP address, it shows 500 internal Server Error. If I test with python manage.py runserver 0.0.0.0:8000 and enter my IP adress:8000/, I can see Django page.
apache2ctl -M I can see wsig_module
Loaded Modules:
core_module (static)
so_module (static)
watchdog_module (static)
http_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
unixd_module (static)
access_compat_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
filter_module (shared)
mime_module (shared)
mpm_event_module (shared)
negotiation_module (shared)
setenvif_module (shared)
status_module (shared)
wsgi_module (shared)
service apache2 status
apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Sat 2016-11-19 03:19:36 UTC; 2min 25s ago
Docs: man:systemd-sysv-generator(8)
Process: 19444 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
Process: 18407 ExecReload=/etc/init.d/apache2 reload (code=exited, status=0/SUCCESS)
Process: 19471 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
Tasks: 55
Memory: 43.2M
CPU: 768ms
CGroup: /system.slice/apache2.service
├─19488 /usr/sbin/apache2 -k start
├─19491 /usr/sbin/apache2 -k start
└─19492 /usr/sbin/apache2 -k start
Nov 19 03:19:36 server4.cango.com systemd[1]: Stopped LSB: Apache2 web server.
Nov 19 03:19:36 server4.cango.com systemd[1]: Starting LSB: Apache2 web server...
Nov 19 03:19:36 server4.cango.com apache2[19471]: * Starting Apache httpd web server apache2
Nov 19 03:19:36 server4.cango.com apache2[19471]: *
Nov 19 03:19:36 server4.cango.com systemd[1]: Started LSB: Apache2 web server.
If I command a2dismod wsgi and then service apache2 restart, it causes an error. It seems I can't restart with disabling wsgi_mod because I set WSGIScriptAlias
Nov 19 03:22:59 server4.cango.com apache2[19746]: * Starting Apache httpd web server apache2
Nov 19 03:22:59 server4.cango.com apache2[19746]: *
Nov 19 03:22:59 server4.cango.com apache2[19746]: * The apache2 configtest failed.
Nov 19 03:22:59 server4.cango.com apache2[19746]: Output of config test was:
Nov 19 03:22:59 server4.cango.com apache2[19746]: AH00526: Syntax error on line 33 of /etc/apache2/sites-enabled/000-def
Nov 19 03:22:59 server4.cango.com apache2[19746]: Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a
Nov 19 03:22:59 server4.cango.com apache2[19746]: Action 'configtest' failed.
Nov 19 03:22:59 server4.cango.com apache2[19746]: The Apache error log may have more information.
Nov 19 03:22:59 server4.cango.com systemd[1]: apache2.service: Control process exited, code=exited status=1
Nov 19 03:22:59 server4.cango.com systemd[1]: Failed to start LSB: Apache2 web server.
-- Subject: Unit apache2.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit apache2.service has failed.
--
-- The result is failed.
Nov 19 03:22:59 server4.cango.com systemd[1]: apache2.service: Unit entered failed state.
Nov 19 03:22:59 server4.cango.com systemd[1]: apache2.service: Failed with result 'exit-code'.
Nov 19 03:23:50 server4.cango.com sudo[19822]: root : TTY=pts/1 ; PWD=/home/cango/jaemyun ; USER=root ; COMMAND=/bin
Nov 19 03:23:50 server4.cango.com sudo[19822]: pam_unix(sudo:session): session opened for user root by root(uid=0)
Well, I wonder what I made a mistake. Still 500 Internal Server Error.
2.Nothing prevents you from using daemon mode for your WSGI application at the same time as using the authnz handlers.
From the link which I mentioned above, it says "if the authentication check is making use of the internals of some Python web framework, it is recommended that the application using that web framework also be run in embedded mode and the same application group"
So I thought I need to use embedded mode with Django framework.
-------------------------- fixed by another comment ----------------------------
I checked error log in apache. There was an error and it seems it has problem to load wsgi script in my django project. Well, above, I changed folder name 'jaemyun' to 'myproject'. there is a wsgi.py file which was automatically made by Django under /home/cango/jaemyun/jaemyun/ path. Why does it say that it can't load it???
No module named 'jaemyun', referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.525510 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] mod_wsgi (pid=11755): Target WSGI script '/home/cango/jaemyun/jaemyun/wsgi.py' cannot be loaded as Python module.
[Sun Nov 20 10:37:24.525600 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] mod_wsgi (pid=11755): Exception occurred processing WSGI script '/home/cango/jaemyun/jaemyun/wsgi.py'.
[Sun Nov 20 10:37:24.525801 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] Traceback (most recent call last):
[Sun Nov 20 10:37:24.525866 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "/home/cango/jaemyun/jaemyun/wsgi.py", line 16, in <module>
[Sun Nov 20 10:37:24.525872 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] application = get_wsgi_application()
[Sun Nov 20 10:37:24.525880 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "/usr/local/pythonenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Sun Nov 20 10:37:24.525885 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] django.setup(set_prefix=False)
[Sun Nov 20 10:37:24.525893 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "/usr/local/pythonenv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
[Sun Nov 20 10:37:24.525909 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Sun Nov 20 10:37:24.525917 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "/usr/local/pythonenv/lib/python3.5/site-packages/django/conf/__init__.py", line 53, in __getattr__
[Sun Nov 20 10:37:24.525921 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] self._setup(name)
[Sun Nov 20 10:37:24.525928 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "/usr/local/pythonenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
[Sun Nov 20 10:37:24.525932 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] self._wrapped = Settings(settings_module)
[Sun Nov 20 10:37:24.525939 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "/usr/local/pythonenv/lib/python3.5/site-packages/django/conf/__init__.py", line 97, in __init__
[Sun Nov 20 10:37:24.525943 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] mod = importlib.import_module(self.SETTINGS_MODULE)
[Sun Nov 20 10:37:24.525950 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "/usr/local/pythonenv/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Sun Nov 20 10:37:24.525954 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] return _bootstrap._gcd_import(name[level:], package, level)
[Sun Nov 20 10:37:24.525961 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Sun Nov 20 10:37:24.525968 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Sun Nov 20 10:37:24.525975 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Sun Nov 20 10:37:24.525982 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Sun Nov 20 10:37:24.525988 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Sun Nov 20 10:37:24.525995 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Sun Nov 20 10:37:24.526002 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Sun Nov 20 10:37:24.526023 2016] [wsgi:error] [pid 11755:tid 140507221055232] [client 124.80.108.6:64058] ImportError: No module named 'jaemyun'
[Sun Nov 20 10:37:24.564690 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] mod_wsgi (pid=11755): Target WSGI script '/home/cango/jaemyun/jaemyun/wsgi.py' cannot be loaded as Python module., referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.564729 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] mod_wsgi (pid=11755): Exception occurred processing WSGI script '/home/cango/jaemyun/jaemyun/wsgi.py'., referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.564889 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] Traceback (most recent call last):, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.564947 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "/home/cango/jaemyun/jaemyun/wsgi.py", line 16, in <module>, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.564953 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] application = get_wsgi_application(), referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.564961 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "/usr/local/pythonenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.564972 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] django.setup(set_prefix=False), referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.564981 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "/usr/local/pythonenv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.564985 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING), referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.564992 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "/usr/local/pythonenv/lib/python3.5/site-packages/django/conf/__init__.py", line 53, in __getattr__, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.564997 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] self._setup(name), referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565004 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "/usr/local/pythonenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565008 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] self._wrapped = Settings(settings_module), referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565015 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "/usr/local/pythonenv/lib/python3.5/site-packages/django/conf/__init__.py", line 97, in __init__, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565019 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] mod = importlib.import_module(self.SETTINGS_MODULE), referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565026 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "/usr/local/pythonenv/lib/python3.5/importlib/__init__.py", line 126, in import_module, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565030 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] return _bootstrap._gcd_import(name[level:], package, level), referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565037 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "<frozen importlib._bootstrap>", line 986, in _gcd_import, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565044 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "<frozen importlib._bootstrap>", line 969, in _find_and_load, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565052 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565059 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565066 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "<frozen importlib._bootstrap>", line 986, in _gcd_import, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565073 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "<frozen importlib._bootstrap>", line 969, in _find_and_load, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565080 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked, referer: http://169.56.70.181/
[Sun Nov 20 10:37:24.565097 2016] [wsgi:error] [pid 11755:tid 140507204269824] [client 124.80.108.6:64057] ImportError: No module named 'jaemyun', referer: http://169.56.70.181/
last change.
wsgi.conf
<IfModule mod_wsgi.c>
WSGIPythonHome /usr/local/pythonenv
WSGIPythonPath /home/cango/jaemyun
I had to set WSGIPythonPath and direct to my django project path. Now it works!
Im a bit stuck. I can't get this configuration to work and I don't know why. The code I site below is from https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04. The reason I get stuck on it is because he named his project directory and his project the same thing. If I am right, then where he is locating files like the settings.py and wsgi.py should be /home/user/myproject/myproject/myproject but I'm not sure anymore because I can't even get it right myself. Earlier in the document he cd's into the directory he created, which would put him in /home/user/myproject. He then proceeds to create a virtual environment, enter it, and run django-admin startproject myproject. So, if all this holds true, at least what I see on my own server tells me that when you start a django project it actually creates two folders with the same name, nested. Am I wrong? Can someone help me straighten the below code out to make more sense?
. . .
Alias /static /home/user/myproject/static
<Directory /home/user/myproject/static>
Require all granted
</Directory>
<Directory /home/user/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-path=/home/user/myproject:/home/user/myproject/myprojectenv/lib/python2.7/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /home/user/myproject/myproject/wsgi.py
</VirtualHost>
This is what I consistently see in my apache log:
[Sun Oct 09 11:48:15.875313 2016] [wsgi:warn] [pid 47964] mod_wsgi: Compiled for Python/3.5.1+.
[Sun Oct 09 11:48:15.875353 2016] [wsgi:warn] [pid 47964] mod_wsgi: Runtime using Python/3.5.2.
[Sun Oct 09 11:48:15.877537 2016] [mpm_prefork:notice] [pid 47964] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Sun Oct 09 11:48:15.877568 2016] [core:notice] [pid 47964] AH00094: Command line: '/usr/sbin/apache2'
[Sun Oct 09 11:48:18.767800 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] mod_wsgi (pid=47967): Target WSGI script '/home/addohm/projects/rtservice/servicesite/servicesite/wsgi.py' cannot be loaded as Python module.
[Sun Oct 09 11:48:18.767851 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] mod_wsgi (pid=47967): Exception occurred processing WSGI script '/home/addohm/projects/rtservice/servicesite/servicesite/wsgi.py'.
[Sun Oct 09 11:48:18.768339 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] Traceback (most recent call last):
[Sun Oct 09 11:48:18.768385 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/home/addohm/projects/rtservice/servicesite/servicesite/wsgi.py", line 16, in <module>
[Sun Oct 09 11:48:18.768389 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] application = get_wsgi_application()
[Sun Oct 09 11:48:18.768395 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Sun Oct 09 11:48:18.768398 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] django.setup()
[Sun Oct 09 11:48:18.768405 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3/dist-packages/django/__init__.py", line 17, in setup
[Sun Oct 09 11:48:18.768408 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Sun Oct 09 11:48:18.768413 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3/dist-packages/django/conf/__init__.py", line 48, in __getattr__
[Sun Oct 09 11:48:18.768423 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] self._setup(name)
[Sun Oct 09 11:48:18.768430 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3/dist-packages/django/conf/__init__.py", line 44, in _setup
[Sun Oct 09 11:48:18.768433 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] self._wrapped = Settings(settings_module)
[Sun Oct 09 11:48:18.768438 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3/dist-packages/django/conf/__init__.py", line 92, in __init__
[Sun Oct 09 11:48:18.768441 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] mod = importlib.import_module(self.SETTINGS_MODULE)
[Sun Oct 09 11:48:18.768446 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Sun Oct 09 11:48:18.768449 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] return _bootstrap._gcd_import(name[level:], package, level)
[Sun Oct 09 11:48:18.768454 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Sun Oct 09 11:48:18.768460 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Sun Oct 09 11:48:18.768466 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Sun Oct 09 11:48:18.768471 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Sun Oct 09 11:48:18.768477 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Sun Oct 09 11:48:18.768483 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Sun Oct 09 11:48:18.768488 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Sun Oct 09 11:48:18.768505 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] ImportError: No module named 'servicesite'
in your /etc/apache2/apache2.conf file add
<Directory /home/dimitris/mysite>
AllowOverride All
Require all granted
</Directory>
your site.conf file in the example i load mysite with virtualenv
WSGIDaemonProcess myp user=dimitris group=dimitris threads=5 python-path=/home/dimitris/myenv/lib/python2.7/site-packages
<VirtualHost *:80>
#ServerName mysite
#ServerAlias mysite
ServerAdmin webmaster#localhost
WSGIProcessGroup myp
WSGIScriptAlias / /home/dimitris/mysite/mysite/wsgi.py
Alias /favicon.ico /home/dimitris/mysite/favicon.ico
Alias /media/ /home/dimitris/mysite/media/
Alias /static/ /home/dimitris/mysite/project-static/
DocumentRoot /home/dimitris/mysite
<Directory /home/dimitris/mysite/>
Order allow,deny
allow from all
</Directory>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
ErrorLog /var/log/mysite-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/mysite-access.log combined
</VirtualHost>
in django wsgi.py file add
import os
DJANGO_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
sys.path.append(DJANGO_PATH)
in the above code replace dimitris with your username
Either you create your project at /home/user or change the apache conf file by appending an extra /myproject wherever you are specifying the path as below:
Alias /static /home/user/myproject/myproject/static
<Directory /home/user/myproject/myproject/static>
Require all granted
</Directory>
<Directory /home/user/myproject/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-path=/home/user/myproject/myproject:/home/user/myproject/myproject/myprojectenv/lib/python2.7/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /home/user/myproject/myproject/myproject/wsgi.py
It was confusing because you created your project inside a myproject folder(same as your project name), rather than creating it somewhere else.