简体   繁体   中英

Replacing static site with Django/Serving static files with mod_wsgi

I have an existing static website that is served via apache. I wanted to add dynamic features to that site so I created a Django app that lives in a subfolder (ie. /django-site/ ). I have this configured like this:

    WSGIDaemonProcess django_site processes=5 threads=5 user=user group=group python-home=path/to/virtualenv
    WSGIScriptAlias /django-site /var/www/django_site/wsgi.py
    <Location /django-site>
    WSGIProcessGroup group
    </Location>

But now I would like to replace certain pages that were originally static pages in the root directory. But I don't want to replace all of the static pages.

I know that Django recommends putting your static files in a subdirectory like /media or /static and Django configured to be the root directory but since I have a long legacy of these static pages being in the root directory and external links to these pages I don't want to change that.

Is there a recommended way to replace these static pages with a dynamic ones?

Here are a few ideas that I have thought of:

  1. Use ProxyPass to replace pages one at a time
  2. Redirect static pages to dynamic versions, change internal links to new dynamic version
  3. Move dynamic site to root, and use something like whitenoise to serve those files

You could use Apache mod_rewrite to keep the existing links functional. The documentation suggests this:

Description: How can we transform a static page foo.html into a dynamic variant foo.cgi in a seamless way, ie without notice by the browser/user.

Solution: We just rewrite the URL to the CGI-script and force the handler to be cgi-script so that it is executed as a CGI program. This way a request to /~quux/foo.html internally leads to the invocation of /~quux/foo.cgi.

RewriteEngine  on
RewriteBase    "/~quux/"
RewriteRule    "^foo\.html$"  "foo.cgi"  [H=cgi-script]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM