所以,我试图通过mod_wsgi
学习django以及尝试使用Angular和Django REST后端在Apache服务器上创建应用程序。目前,我遇到了静态文件的问题。当应用程序在127.0.0.1:8000
上使用Django工具运行时,Everyhing是可以的,但是当我通过Apache加载它时 - 我缺少静态,所以输出看起来非常原始:
我试图用manage.py collectstatics
收集静力学,试图在python dirs中定义一个带有静力学的目录 - 什么都没有:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'DjangoApp/static/')
STATICFILES_DIRS = [
'C:/Users/<user>/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static',
]
Apache虚拟主机设置:
<VirtualHost 127.0.0.1:8081>
##ServerAdmin webmaster@dummy-host.example.com
WSGIScriptAlias / "D:/genesi5/Coding/www/django/wsgi_handler.wsgi"
DocumentRoot "D:/genesi5/Coding/www/django"
ServerName DjangoApp
ServerAlias DjangoApp
ErrorLog "logs/myapp/error.log"
CustomLog "logs/myapp/access.log" common
<Directory "D:/genesi5/Coding/www/django">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
的httpd.conf:
LoadModule wsgi_module "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
<IfModule wsgi_module>
LoadFile "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/python36.dll"
WSGIPythonHome "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32"
WSGIPassAuthorization On
</IfModule>
你能建议一个解决方案吗?
答案 0 :(得分:1)
您必须在Apache2.conf
中声明许多内容才能使用mod_wsgi
WSGIScriptAlias / /path_to_wsgi.py
WSGIPythonPath /path_to_your_project
Alias /static/ /path_to_your_static_directory
<Directory /path_to_your_static_directory>
Require all granted
</Directory>
<Directory /path_to_your_project_directory>
<Files wsgi.py>
#Options Indexes FollowSymLinks
#Require all granted
#SetEnvIfNoCase Host .+ VALID_HOST
Order deny,allow
Allow from all
#Allow from env=VALID_HOST
</Files>
</Directory>
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /srv/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
这是Linux的一个例子,但与Windows相同;)
答案 1 :(得分:0)
所以,我必须在虚拟主机设置中添加额外的别名,并且此刻它有点工作:
<VirtualHost 127.0.0.1:8081>
##ServerAdmin webmaster@dummy-host.example.com
WSGIScriptAlias / "D:/genesi5/Coding/www/django/wsgi_handler.wsgi"
DocumentRoot "D:/genesi5/Coding/www/django"
ServerName DjangoApp
ServerAlias DjangoApp
ErrorLog "logs/myapp/error.log"
CustomLog "logs/myapp/access.log" common
Alias /static "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static"
<Directory "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static">
Require all Granted
</Directory>
<Directory "D:/genesi5/Coding/www/django">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>