我们使用apache,mod_php和mod_wsgi来提供一个中央的wordpress站点,一些path由Django提供动力,例如这些页面可能由Wordpress提供动力:
oursite.com/ oursite.com/video/
但是这些URL可能是由Django支持的:
oursite.com/our-cool-django-app/ oursite.com/schedule/
现在,我们使用一长串WSGIScriptAlias将特定的path映射到Django。 这令人讨厌,劳动密集。
那么,有没有办法可以configuration这样的事情:
我对Apache解决scheme特别感兴趣,但会考虑替代scheme。
这是为了回应你的娱乐select。
我已经使用php5-fpm for WordPress在Nginx背后的同一个域中托pipe了Django和WordPress,依靠Nginx的X-Accel-Redirect将未定义的URL返回到WordPress 上游 。
Nginxconfiguration以WordPress应该处理的已知模式开始:索引页面,一些顶级内容页面或顶级部分,和/或博客文章的模式。 这意味着大多数的WordPressurl可以被十几个或更less的URL模式所捕获。
其他的一切都被路由到Django上游。
新的网页或WordPress网站的变化呢? Django应用程序使用自定义404处理程序将请求redirect到上游的WordPress,而不是更新每个WordPress页面或节添加的URL模式。
def page_not_found(request): """ A 404 view that redirects to the WordPress installation. """ try: new_url = Redirect.objects.get(old_path=request.get_full_path()) except Redirect.DoesNotExist: pass else: return redirect(new_url.new_path) if not settings.WORDPRESS_REDIRECT: return render(request, "404.html", {}) response = HttpResponse() response['X-Accel-Redirect'] = '/wordpress/' return response
通过redirect请求,redirect中间件不会“看到”任何404错误,所以如果你想使用redirectfunction,应该在这里添加。 /wordpress/ location被定义为Nginxconfiguration中的内部位置。
location /wordpress/ { internal; try_files $uri $uri/ /index.php; }
我已经写了一些关于使用X-Accel-Redirects用于此目的的更多信息 ,但是我认识到这并不能解答具体的问题。
希望它给你一些想法,可以使用X-Sendfile来做类似mod_php和mod_wsgi事情。
读:
使用AddHandler / mod_rewrite方法。
如果一个URL不能被你的PHP应用程序处理,因为没有对应的.php文件,那么它将会通过你的WSGI应用程序。