APACHE-DJANGO-WSGI部署
APACHE-DJANGO-WSGI Deployment
我有一个位于
的 django 应用程序
/home/user/myapp
我正在尝试 运行 使用 apache2 和 WSGI 的应用程序。当前,apache2 配置位于 /etc/apache2/apache2.conf 并且该目录与我的网站相关
<VirtualHost website.com:80>
ServerName website.com
ServerAlias www.website.com
ServerAdmin email@website.com
DocumentRoot /home/user/myapp/static
WSGIScriptAlias / /var/www/website-directory/django.wsgi
<Directory /home/user/myapp/static>
Order allow,deny
Allow from all
</Directory>
Alias /robots.txt /var/www/webisite-directory/robots.txt
Alias /favicon.ico /var/www/webisite-directory/favicon.ico
Alias /images /home/user/myapp/images
Alias /static /home/user/myapp/static
ErrorLog /var/www/webisite-directory/error.log
CustomLog /var/www/webisite-directory/access.log combined
</VirtualHost>
我的django.wsgi是
import os
import sys
sys.path.append('/home/user/myapp')
os.environ['DJANGO_SETTINGS_MODULE'] = '/myapp_directory/settings'
sys.executable = '/usr/lib/python2.7/dist-packages'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
这是我的错误日志
user@ubuntu:/var/www/website-directory$ vim error.log
[Thu Mar 30 01:25:10.060478 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] self.load_middleware(), referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060490 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 48, in load_middleware, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060509 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] if settings.MIDDLEWARE is None:, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060521 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 53, in __getattr__, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060558 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] self._setup(name), referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060570 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060585 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] self._wrapped = Settings(settings_module), referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060597 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 97, in __init__, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060612 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] mod = importlib.import_module(self.SETTINGS_MODULE), referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060624 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060642 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] __import__(name), referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060705 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] ImportError: Import by filename is not supported., referer: http://www.mywebsite
DJANGO_SETTINGS_MODULE顾名思义应该是模块,而不是路径。
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp_directory.settings'
我有一个位于
的 django 应用程序/home/user/myapp
我正在尝试 运行 使用 apache2 和 WSGI 的应用程序。当前,apache2 配置位于 /etc/apache2/apache2.conf 并且该目录与我的网站相关
<VirtualHost website.com:80>
ServerName website.com
ServerAlias www.website.com
ServerAdmin email@website.com
DocumentRoot /home/user/myapp/static
WSGIScriptAlias / /var/www/website-directory/django.wsgi
<Directory /home/user/myapp/static>
Order allow,deny
Allow from all
</Directory>
Alias /robots.txt /var/www/webisite-directory/robots.txt
Alias /favicon.ico /var/www/webisite-directory/favicon.ico
Alias /images /home/user/myapp/images
Alias /static /home/user/myapp/static
ErrorLog /var/www/webisite-directory/error.log
CustomLog /var/www/webisite-directory/access.log combined
</VirtualHost>
我的django.wsgi是
import os
import sys
sys.path.append('/home/user/myapp')
os.environ['DJANGO_SETTINGS_MODULE'] = '/myapp_directory/settings'
sys.executable = '/usr/lib/python2.7/dist-packages'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
这是我的错误日志
user@ubuntu:/var/www/website-directory$ vim error.log
[Thu Mar 30 01:25:10.060478 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] self.load_middleware(), referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060490 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 48, in load_middleware, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060509 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] if settings.MIDDLEWARE is None:, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060521 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 53, in __getattr__, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060558 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] self._setup(name), referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060570 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060585 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] self._wrapped = Settings(settings_module), referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060597 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 97, in __init__, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060612 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] mod = importlib.import_module(self.SETTINGS_MODULE), referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060624 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module, referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060642 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] __import__(name), referer: http://www.mywebsite
[Thu Mar 30 01:25:10.060705 2017] [wsgi:error] [pid 7235:tid 139856399259392] [client 98.16.70.181:51796] ImportError: Import by filename is not supported., referer: http://www.mywebsite
DJANGO_SETTINGS_MODULE顾名思义应该是模块,而不是路径。
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp_directory.settings'