繁体   English   中英

用 Django 替换 static 站点/用 mod_wsgi 服务 static 文件

[英]Replacing static site with Django/Serving static files with mod_wsgi

我有一个现有的 static 网站,通过 apache 提供服务。 我想为该站点添加动态功能,因此我创建了一个 Django 应用程序,该应用程序位于子文件夹(即/django-site/ )中。 我有这样的配置:

    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>

但是现在我想替换根目录中原本是 static 页面的某些页面。 但我不想替换所有 static 页面。

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不想改变。

是否有推荐的方法将这些 static 页面替换为动态页面?

以下是我想到的一些想法:

  1. 使用ProxyPass一次替换一页
  2. 将 static 页面重定向到动态版本,将内部链接更改为新的动态版本
  3. 将动态站点移动到根目录,并使用诸如whitenoise 之类的东西来提供这些文件

您可以使用 Apache mod_rewrite 来保持现有链接的功能。 文档表明这一点:

描述:我们如何以无缝方式将 static 页面 foo.html 转换为动态变体 foo.cgi,即无需浏览器/用户通知。

解决方案:我们只是将URL改写为CGI-script,并强制handler为cgi-script,这样就可以作为CGI程序执行了。 这样,对 /~quux/foo.html 的请求会在内部导致调用 /~quux/foo.cgi。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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