This is in response to your entertainment of alternatives.
I've hosted Django and WordPress on the same domain behind Nginx using php5-fpm
for WordPress and relying on Nginx's X-Accel-Redirect
to return undefined URLs to the WordPress upstream.
The Nginx configuration starts with known patterns which WordPress should handle: an index page, a few top-level content pages or top-level sections, and/or the pattern for blog posts. This means most WordPress URLs can be caught with a dozen or fewer URL patterns.
Everything else is routed to the Django upstream.
What about new pages or changes to the WordPress site? Rather than update the URL patterns for every WordPress page or section added, the Django app uses a custom 404 handler to redirect the request to the WordPress upstream.
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
By redirecting the requests the redirect middleware won't "see" any 404 errors, so if you want to use the redirect feature it should be added here. The /wordpress/
location is defined as an internal location in the Nginx configuration.
location /wordpress/ {
internal;
try_files $uri $uri/ /index.php;
}
I've written a little bit more about using X-Accel-Redirects for this purpose, though I recognize this doesn't answer the specific question.
Hopefully it gives you some ideas of you could employ X-Sendfile
to do something similar with mod_php
and mod_wsgi
.