tomcat - 使用 Apache 在 Lucee (tomcat) 中启用基本身份验证

标签 tomcat authentication coldfusion lucee

我将 apache 与 Lucee (tomcat) 一起使用。我有一个开发站点,我希望它支持基本身份验证。我有 apache 配置和非 ColdFusion 页面需要并提示进行身份验证。当我导航到 CF 页面时,不需要基本身份验证。

我需要修改什么 Tomcat/Lucee 配置文件才能在设置附加基本身份验证时使用 apache 基本身份验证?

我正在运行 Apache/2.4.10 (Debian)

这是我的站点配置文件:

<VirtualHost *:80>
    ServerName dev.mysite.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/mysite.com/dev/docroot

    <Directory /var/www/mysite.com/dev>
      Options Indexes FollowSymLinks
      AllowOverride All
      AuthName "Secured Development Environment"
      AuthType Basic
      AuthUserFile /etc/apache2/.htpasswd
      Require valid-user
      DirectoryIndex index.cfm index.html
    </Directory>


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

这是 Lucee 添加到我的 apache2.conf 文件中的内容

<IfModule mod_proxy.c>
    ProxyPreserveHost On
    ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ http://127.0.0.1:8888/$1$2
    ProxyPassMatch ^/(.+\.cfchart)(/.*)?$ http://127.0.0.1:8888/$1$2
    ProxyPassMatch ^/(.+\.cfml)(/.*)?$ http://127.0.0.1:8888/$1$2
    # optional mappings
    #ProxyPassMatch ^/flex2gateway/(.*)$ http://127.0.0.1:8888/flex2gateway/$1
    #ProxyPassMatch ^/messagebroker/(.*)$ http://127.0.0.1:8888/messagebroker/$1
    #ProxyPassMatch ^/flashservices/gateway(.*)$ http://127.0.0.1:8888/flashservices/gateway$1
    #ProxyPassMatch ^/openamf/gateway/(.*)$ http://127.0.0.1:8888/openamf/gateway/$1
    #ProxyPassMatch ^/rest/(.*)$ http://127.0.0.1:8888/rest/$1
    ProxyPassReverse / http://127.0.0.1:8888/
</IfModule>

这是我根据推荐的更新配置

我根据您的建议更新了我的配置,但并没有解决问题。

<VirtualHost *:80>
    ServerName dev.mysite.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/mysite.com/dev/docroot

    <Directory /var/www/mysite.com/dev>
      Options Indexes FollowSymLinks
      AllowOverride All
      AuthName "Secured Development Environment"
      AuthType Basic
      AuthUserFile /etc/apache2/.htpasswd
      Require valid-user
      DirectoryIndex index.cfm index.html
    </Directory>


  <IfModule mod_proxy.c>
    ProxyPreserveHost On
    ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ http://127.0.0.1:8888/$1$2
    ProxyPassMatch ^/(.+\.cfchart)(/.*)?$ http://127.0.0.1:8888/$1$2
    ProxyPassMatch ^/(.+\.cfml)(/.*)?$ http://127.0.0.1:8888/$1$2
    ProxyPassReverse / http://127.0.0.1:8888/
  </IfModule>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

这不起作用,我不确定它有什么不同,因为虚拟主机包含在 IfModule 之前

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

最佳答案

请求在到达您的 VirtualHost 之前被代理到 Tomcat。移动 <IfModule>东西进入 <VirtualHost><Directory>之后定义。您需要为每个虚拟主机执行此操作,因此您可能希望将其弹出到一个单独的文件中,然后使用 Include 指令将其包含在内。

也尝试加入:

<Limit GET POST>
    order deny,allow
    satisfy any
    deny from all
    require valid-user
</Limit>

就在Require valid-user之后行。

关于tomcat - 使用 Apache 在 Lucee (tomcat) 中启用基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42999730/

相关文章:

java - 在 Eclipse 中,当所有三个项目都需要 servlet-api.jar 时,如何让 tomcat 运行两个连接的项目?

spring - Tomcat 9 Spring MVC 应用程序 JS 文件使用 header text/html 而不是 application/javascript 下载

c++ - 使用 HttpSendRequest 强制进行基本身份验证?

ruby-on-rails - 我如何在没有登录的情况下注册?

php - 将 PHP PUT HTTP 请求转换为 ColdFusion

java - 运行 Spring WebApp 时代码状态 406

java - 是否可以在同一个 Tomcat 实例上运行多个不同的 war 文件?

asp.net-mvc - 用于存储用户上次登录信息的良好设计模式是什么?

mysql - 选择和更新记录时查询为空错误?

mysql - 问题 仅当表中尚不存在时才插入值