将 httpd.conf 迁移到 .htaccess?
我有一个如下所示的 httpd.conf
文件:
Alias /robots.txt /var/www/tech_eval/static/robots.txt
Alias /favicon.ico /var/www/tech_eval/static/favicon.ico
AliasMatch /([^/]*\.css) /var/www/tech_eval/static/styles/$1
Alias /media/ /var/www/tech_eval/static/media/
<Directory /var/www/tech_eval/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /tech_eval /var/www/tech_eval/scripts/django.wsgi
<Directory /var/www/tech_eval/scripts>
Order allow,deny
Allow from all
</Directory>
这对于我的 tech_eval
项目运行良好,但它开始导致其他站点出现问题。我认为将所有这些内容移动到位于 tech_eval
文件夹中的 .htaccess
文件中可能是合适的,这样就不会引起问题。不过,我认为从 .htaccess
运行时,所有这些选项都不会起作用,对吗? 我的选择是什么?我的意思是,我可以通过在所有内容前加上 tech_eval
前缀来解决这个问题,但最终我的所有网站都会有一个大的主文件,并且它会只是变得一团糟。
I have a httpd.conf
file that looks like this:
Alias /robots.txt /var/www/tech_eval/static/robots.txt
Alias /favicon.ico /var/www/tech_eval/static/favicon.ico
AliasMatch /([^/]*\.css) /var/www/tech_eval/static/styles/$1
Alias /media/ /var/www/tech_eval/static/media/
<Directory /var/www/tech_eval/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /tech_eval /var/www/tech_eval/scripts/django.wsgi
<Directory /var/www/tech_eval/scripts>
Order allow,deny
Allow from all
</Directory>
This works fine for my tech_eval
project, but it's starting to cause problems with other sites. I think it might be appropriate me for to move all this stuff to a .htaccess
file located in the tech_eval
folder so that it doesn't cause problems. Although, I don't think all these options will work when ran from a .htaccess
will they? What are my options? I mean, I could fix this by prefixing everything with tech_eval
but then I'd wind up with one big master file for all my sites and it would just become a big mess.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上并不太清楚您要解决什么问题。您为什么首先使用该配置?看起来您只是从 mod_wsgi 文档中复制了它,而不了解每个位的作用,并在它甚至不适合您的设置时开始使用它。具体来说,mod_wsgi 文档中的示例是一个通用示例,不一定适合 Django。
因此,与其尝试修复该配置来满足某些未知的目标,只需描述您需要什么,然后就会告诉您应该使用什么正确的配置。
更新 1
根据我下面的评论,也许然后使用:
只需抛弃 robots.txt 和 favicon.ico,或者至少不要从子 URL 站点获取它们,只需将它们直接粘贴在 DocumentRoot 目录中,并使用真正完整的那些的网站。
我认为 Django 设置模块中的“ADMIN_MEDIA_PREFIX”需要更改为“/tech_eval/media/”。
对于 Django 来说,你甚至不需要 CSS 别名,这就是最初作为展示概念的通用示例,而不是对于 Django 来说正确的东西。
无论如何,所有内容都位于“/tech_eval”下,并且不应干扰同一站点上的其他应用程序。
It isn't actually too clear what problem you are trying to solve. Why are you even using that configuration in the first place? It looks like you just copied it from mod_wsgi documentation without understanding what each bit does and started using it when it isn't even appropriate for your setup. Specifically that example in mod_wsgi documentation was a generic example and not necessarily suited for Django.
So, rather that trying to fix that configuration to meet some unknown goal, just describe what you need and will tell you what the proper configuration is that you should be using.
UPDATE 1
Per my comment below, perhaps then use:
Just ditch robots.txt and favicon.ico, or at least don't get them from sub URL site and just stick them direct in the DocumentRoot directory and use those which truly are for whole of site.
I think it is 'ADMIN_MEDIA_PREFIX' in Django settings module that you then need to change to '/tech_eval/media/'.
For Django don't think you even need to CSS alias and that is where this was originally a generic example to show concepts rather than be something which was correct for Django.
Anyway, everything is then under '/tech_eval' and shouldn't interfere with other applications on same site.
使用 VirtualHosts 来限制这些行的范围,并使用每个虚拟主机的 include 来组织您的配置文件并防止其变得笨重。
Use VirtualHosts to limit the scope of these lines, and an include per virtual host to organize your config files and keep it from growing unwieldy.