[英]deploy django webserver on apache
I have tested my blog website using: 我已经使用以下方法测试了我的博客网站:
python manage.py runserver
Everything is correct. 一切都正确。 Now I want to deploy my blog site on apache.
现在,我想在apache上部署我的博客网站。 But I cannot configure apache with django correctly.
但是我无法正确地用Django配置apache。 Basicly, my blog structure is the following:
基本上,我的博客结构如下:
├── blog
│ ├── __init__.py
│ ├── models.py
│ ├── static
│ │ └── blog
│ │ ├── css
│ │ ├── images
│ │ └── js
│ ├── templates
│ │ └── blog
│ │ ├── base.html
│ │ ├── index.html
│ ├── templatetags
│ │ ├── custom_filter.py
│ │ ├── __init__.py
│ ├── tests.py
│ ├── urls.py
│ ├── views.py
├── blogC
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── wsgi.py
├── manage.py
└── usermanage
├── admin.py
├── __init__.py
├── models.py
├── tests.py
└── views.py
I have installed the apache, mod_wsgi and database. 我已经安装了apache,mod_wsgi和数据库。 My question is the django middleware will look for static files automatically.
我的问题是django中间件将自动查找静态文件。 Should I add the path to the static files in the httpd.conf?
我应该将路径添加到httpd.conf中的静态文件吗? How should I write the configure file?
我应该如何编写配置文件? I follow the instruction on django official website.
我按照django官方网站上的说明进行操作。 But it turned out the apache service cannot restart, so I must configure it wrong.
但是事实证明apache服务无法重新启动,因此我必须配置错误。
Update the last several lines of the error.log: 更新error.log的最后几行:
[Tue Feb 10 10:02:08.796042 2015] [core:error] [pid 6610] (13)Permission denied: [client 113.240.234.213:14433] AH00035: access to /phppath/php5 denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
[Tue Feb 10 10:02:11.700382 2015] [core:error] [pid 5220] (13)Permission denied: [client 113.240.234.213:15162] AH00035: access to /local-bin/php denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
[Tue Feb 10 10:02:12.407788 2015] [core:error] [pid 5257] (13)Permission denied: [client 113.240.234.213:15339] AH00035: access to /local-bin/php5 denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
[Tue Feb 10 10:02:13.118587 2015] [core:error] [pid 5221] (13)Permission denied: [client 113.240.234.213:15501] AH00035: access to / denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
[Tue Feb 10 11:14:12.291824 2015] [core:error] [pid 5218] (13)Permission denied: [client 205.145.18.5:47369] AH00035: access to / denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
[Tue Feb 10 11:14:14.319037 2015] [core:error] [pid 6308] (13)Permission denied: [client 205.145.18.5:57326] AH00035: access to / denied (filesystem path '/home/ec2-user') because search permissions are missing on a component of the path
Here is a possible apache config: 这是一个可能的apache配置:
WSGIDaemonProcess blog processes=2 threads=15
WSGIScriptAlias / /path/to/project/blog/blogC/wsgi.py
<Directory /path/to/project/>
WSGIProcessGroup blog
WSGIApplicationGroup %{GLOBAL}
Options All
AllowOverride All
Require all granted
</Directory>
Alias /media/ /path/to/project/media/
<Directory /path/to/project/media/>
Options FollowSymLinks MultiViews
Order deny,allow
Allow from all
</Directory>
Alias /static/ /path/to/project/static/
<Directory /path/to/project/static/>
Options FollowSymLinks MultiViews
Order allow,deny
Allow from all
</Directory>
Also create a static
and media
folders in your projects root folder and set them in settings.py
: 还要在项目的根文件夹中创建一个
static
和media
文件夹,并在settings.py
中进行settings.py
:
import os
BASE_PATH = os.path.join(os.path.dirname(__file__), '..')
MEDIA_ROOT = os.path.join(BASE_PATH, 'media/')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_PATH, 'static/')
STATIC_URL = '/static/'
Then collect all static files into provided directory (this will link static files from all apps into one location): 然后将所有静态文件收集到提供的目录中(这会将所有应用程序的静态文件链接到一个位置):
./manage.py collectstatic --link
Also make sure apache has permissions to write into media folder, so files can be uploaded: 还要确保apache有权写入媒体文件夹,以便可以上传文件:
sudo chown -R www-data:www-data /path/to/project/media
Now you gotta make sure your wsgi.py
is configured correctly: 现在,您必须确保正确配置了
wsgi.py
:
import os, sys
## apache/mod_wsgi cannot find the path without it!
path = os.path.split(os.path.dirname(__file__))[0]
if path not in sys.path:
sys.path.append(path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blogC.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
That should be it. 应该是这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.