在Dreamhost上使用带有Django的.htaccess的PassengerEnabled Off和密码保护目录

时间:2022-09-16 23:01:46

I have a website built using Django on Dreamhost deployed successfully with Passenger and Apache. I have a set of static HTML pages that is being served in a remapped sub-directory called /demo/. By adding a .htaccess file to the /demo/ directory with this line:

我在Dreamhost上使用Django构建了一个使用Passenger和Apache成功部署的网站。我有一组静态HTML页面,这些页面在名为/ demo /的重映射子目录中提供。通过使用以下行将.htaccess文件添加到/ demo /目录:

PassengerEnabled off

I was able to bypass Django and serve the static pages in the /demo/ directory. I would like to add password protection to the /demo/ pages without editing the Django python files, but was unable to do so by adding the following lines to the .htaccess file (both above and below the PassengerEnabled off line:

我能够绕过Django并在/ demo /目录中提供静态页面。我想在没有编辑Django python文件的情况下为/ demo / pages添加密码保护,但是无法通过在.htaccess文件中添加以下行来实现这一点(在PassengerEnabled离线的上方和下方:

AuthUserFile /public/demo/.htpasswd
AuthGroupFile /dev/null
AuthName "Private Demo Area"
AuthType Basic
require valid-user

I am not forced to use the .htaccess file approach and was wondering how do I configure the static file directory to not be processed by Django but also be password protected? Thanks!

我没有*使用.htaccess文件方法,并想知道如何配置静态文件目录不被Django处理,但也受密码保护?谢谢!

1 个解决方案

#1


1  

I found a solution which involved creating a subdomain instead of trying to serve the static files through Django and Passenger through a remapped sub-directory. Here is what I did:

我找到了一个解决方案,它涉及创建子域而不是尝试通过重新映射的子目录通过Django和Passenger提供静态文件。这是我做的:

  • Created subdomain demo.domain.com in dreamhost web panel
  • 在dreamhost web面板中创建了子域demo.domain.com

  • Added the .htaccess file to the root directory of the subdomain:

    将.htaccess文件添加到子域的根目录:

    AuthUserFile /public/demo/.htpasswd AuthGroupFile /dev/null AuthName "Private Demo Area" AuthType Basic require valid-user

    AuthUserFile /public/demo/.htpasswd AuthGroupFile / dev / null AuthName“Private Demo Area”AuthType Basic需要有效用户

That did the trick, but the domain for my demo is now demo.domain.com instead of domain.com/demo/. I am ok with this trade off and this was the only solution I could find on dreamhost shared hosting.

这样做了,但我演示的域名现在是demo.domain.com而不是domain.com/demo/。我没关系这个权衡,这是我在dreamhost共享主机上找到的唯一解决方案。

#1


1  

I found a solution which involved creating a subdomain instead of trying to serve the static files through Django and Passenger through a remapped sub-directory. Here is what I did:

我找到了一个解决方案,它涉及创建子域而不是尝试通过重新映射的子目录通过Django和Passenger提供静态文件。这是我做的:

  • Created subdomain demo.domain.com in dreamhost web panel
  • 在dreamhost web面板中创建了子域demo.domain.com

  • Added the .htaccess file to the root directory of the subdomain:

    将.htaccess文件添加到子域的根目录:

    AuthUserFile /public/demo/.htpasswd AuthGroupFile /dev/null AuthName "Private Demo Area" AuthType Basic require valid-user

    AuthUserFile /public/demo/.htpasswd AuthGroupFile / dev / null AuthName“Private Demo Area”AuthType Basic需要有效用户

That did the trick, but the domain for my demo is now demo.domain.com instead of domain.com/demo/. I am ok with this trade off and this was the only solution I could find on dreamhost shared hosting.

这样做了,但我演示的域名现在是demo.domain.com而不是domain.com/demo/。我没关系这个权衡,这是我在dreamhost共享主机上找到的唯一解决方案。