我已经在我的机器上安装了 Tomcat,它运行良好。我能够登录到管理管理器。我已经部署了一个.war
可以在 Tomcat 管理器上查看的文件。该文件的名称是shim
(实际上我正在安装freeshim
)。
当我尝试使用浏览器访问 shim 时,192.168.1.65:8080/shim
我获得了shim
. 这是我得到的消息:
这是 FreeSHIM 的 Web 管理界面。Web 服务位于“此处”。
当我单击“此处”以配置 Freeshim 时,出现错误:
HTTP 状态 403 - 对请求资源的访问已被拒绝。
我哪里错了?如何更改此权限?
HTTP 状态 403(对请求的资源的访问已被拒绝)可能表明您输入了 3 个以上不正确的凭据(尝试其他 Web 浏览器)或者您的配置存在问题。
conf/tomcat-users.xml
如果您没有更改任何配置文件,请检查安装中的文件( locate tomcat-users.xml
)。该文件必须包含允许您使用 Tomcat Web 应用程序的凭据。
例如,要将 manager-gui 角色添加到名为 、tomcat
密码为 的用户s3cret
,请将以下内容添加到上面列出的配置文件中:
<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
Run Code Online (Sandbox Code Playgroud)
然后您可以访问您的网络应用程序管理器/manager/html
(例如配置更改后重新加载)。
了解更多:管理器应用程序操作方法
如果您尝试实现自己的安全约束(在web.xml
),请尝试以下示例(在</web-app>
结束之前):
<!-- This security constraint protects your webapp interface. -->
<login-config>
<!-- Define the Login Configuration -->
<auth-method>BASIC</auth-method>
<realm-name>Webapp</realm-name>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>Admin</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
<!-- Specifying a Secure Connection -->
<user-data-constraint>
<!-- transport-guarantee can be CONFIDENTIAL (forced SSL), INTEGRAL, or NONE -->
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<!-- Authorization, see: tomcat-users.xml -->
<security-role>
<role-name>*</role-name>
</security-role>
Run Code Online (Sandbox Code Playgroud)
如果您仍然遇到问题,请尝试:
catalina.sh configtest
或xmlstarlet val /etc/tomcat?/*.xml /var/lib/tomcat7/webapps/*/WEB-INF/*.xml
,<url-pattern>
匹配项<security-constraint>
或 设置为/*
,/var/log/tomcat7
),INFO
-> FINE
/ FINEST
)logging.properties
或log4j.properties
(INFO、SEVERE、WARNING、INFO、CONFIG、FINE、FINER、FINEST 或 ALL),重新启动 Tomat 并检查日志,sudo lsof | grep -E "java.*(out|txt|log)$"
, tail -f /var/log/tomcat7/*.log /var/log/tomcat7/*.txt /var/log/tomcat7/*.out
),log4j
日志系统时,请确保通过将 libs 和放入正确的文件夹并配置它来正确初始化它,log4j.properties
使用 cURL 测试 BASIC 身份验证:
没有凭证:
$ curl -vv http://example.com:8983/solr/
Run Code Online (Sandbox Code Playgroud)
通常请求应返回HTTP/1.1 401 Unauthorized,并且“ WWW-Authenticate ”标头应指示需要基本身份验证。
与凭据:
$ curl -vv -u tomcat:tomcat http://example.com:8983/solr/
Run Code Online (Sandbox Code Playgroud)
该请求应与“Authorization”标头一起发送,并且应该进行身份验证。如果您的凭据无效,您应该得到:HTTP/1.1 401 Unauthorized。如果用户已通过身份验证,但无权查看资源,您应该得到:HTTP/1.1 403 Forbidden。
可能由于多次失败的身份验证尝试而激活了用户锁定机制(LockOutRealm),
手动停止并运行 Tomcat(与:中的方式相同ps wuax | grep ^tomcat
),例如:
# ps wuax | grep ^tomcat
tomcat7 884 /usr/lib/jvm/java-7-openjdk-amd64/bin/java -Djava.util.logging.config.file=/var/lib/tomcat7/conf/logging.properties ... org.apache.catalina.startup.Bootstrap start
$ /etc/init.d/tomcat7 stop
$ sudo sudo -u tomcat7 /usr/lib/jvm/java-7-openjdk-amd64/bin/java ... -Dorg.apache.catalina.level=FINEST org.apache.catalina.startup.Bootstrap start
Run Code Online (Sandbox Code Playgroud)
或者开始使用catalina.sh
如下脚本:
$ . /etc/default/tomcat7
$ export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 CATALINA_HOME=/usr/share/tomcat7 CATALINA_BASE=/var/lib/tomcat7 CATALINA_PID=/var/run/tomcat7.pid CATALINA_TMPDIR=/tmp LOGGING_CONFIG="-Dorg.apache.catalina.level=FINEST"
$ /usr/share/tomcat7/bin/catalina.sh run
Run Code Online (Sandbox Code Playgroud)
或者在调试模式下:
$ JPDA_SUSPEND=y catalina.sh jpda start
Run Code Online (Sandbox Code Playgroud)
并检查你的catalina.out
日志。
最后的手段是通过以下方式调试进程:sudo strace -fp PID
。