我有一个WordPress的博客,假设它的地址就像yakblog.org ,它是一个安装在Ubuntu 12.04服务器上的Wordpress博客。
现在,我想运行一个Django应用程序作为我的博客的子页面之一,所以我可以像这样访问它: yakblog.org/testproject 。
这是确切的情况: https : //community.webfaction.com/questions/17758/wordpress-on-root-domain-django-in-subdirectory (虽然我不使用webfaction)。 此外,我试过这里给出的解决scheme: https : //stackoverflow.com/questions/26013379/run-django-project-inside-wordpress-on-suburl-of-wordpress-using-apache-and-mod ,但后来我有一个WordPress的消息: This is somewhat embarrassing, isn't it?
但是,我遇到了一些这样做的问题,我不确定是否可以用我的设置。 好吧,我做了以下工作来实现我所需要的:
/var/www/yak/public_html创build一个Django项目,所以在/var/www/yak/public_html我有这样的结构:
然后,在我的/etc/apache2/apache2.conf文件中添加一行WSGIPythonPath /var/www/yak/public_html/testproject
这是我的虚拟主机代码:
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName yakblog.org/testproject ServerAlias www.yakblog.org/testproject #RedirectPermanent / http://yakblog.org/testproject WSGIScriptAlias /testproject /var/www/yak/public_html/testproject/testproject/wsgi.py DocumentRoot /var/www/yak/public_html/testproject/ <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/yak/public_html/testproject/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog /home/yak/logs/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /home/yak/logs/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>
问题是当进入http://yakblog.org/testproject我看不到我的应用程序,但只有在这个目录中的文件的列表:
问题在这里
<Directory /var/www/yak/public_html/testproject/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>
您正在显示该文件夹的内容,而不是运行实际的应用程序。
你可以看文档来设置你的服务器https://docs.djangoproject.com/es/1.9/howto/deployment/wsgi/modwsgi/
你需要做的是安装mod_wsgi并将其添加到
<Directory /path/to/mysite.com/mysite> <Files wsgi.py> Require all granted </Files> </Directory>
在那里你只提供wsgi.py和wsgi.py它用来为你的应用程序提供服务。