gpt4 book ai didi

tomcat 前面的 apache 和重定向无法正常工作

转载 作者:行者123 更新时间:2023-11-28 22:01:42 25 4
gpt4 key购买 nike

我有一个在亚马逊 Linux 服务器上运行的 grails 应用程序,我有一个 tomcat 并在前面添加了一个 apache,以便将 domain.com 重定向到 www.domain.com。经过大量谷歌搜索后,我可以让它工作,但后来我意识到,当我输入 domain.com 时,它被重定向到 www.domain.com//(末尾有两个斜杠)。再次谷歌搜索我可以使它在位于/etc/httpd/conf.d 的 tomcat.conf 文件中使用以下配置:

<VirtualHost *:80>
ServerName www.domain.com
ServerAlias domain.com
ProxyRequests Off
ProxyPreserveHost On

ErrorLog /var/log/httpd/tomcat.error.log
CustomLog /var/log/httpd/tomcat.log combined

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^/(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</VirtualHost>

问题是,现在有时一切都按预期工作,但有时当我访问 domain.com 时,我会看到一个下载框,要求下载 DMS 文件,有时它可以工作,但显示两个斜杠,而且它也发生了当我输入 domain.com 时,它被转换为 www.www.domain.com(两个 www),所以不确定是什么让这项工作有时正常,有时不正常。

查看 tomcat 日志我可以看到这个,我认为它可能是相关的:

Jul 05, 2016 11:02:20 PM org.apache.coyote.AbstractProcessor     setErrorState
INFO: An error occurred in processing while on a non-container thread. The connection will be closed immediately
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)

编辑 2:我删除了从 domain.com 重定向到 www.domain.com 的行,但我仍然遇到这个问题,随机要求我下载文件而不是显示该站点,并且我可以在 JS 控制台中看到下一条消息:资源被解释为文档但以 MIME 类型 application/octet-stream 传输:“domain.com”

编辑:澄清一下,我在这篇文章中将我的域名更改为通用“域”

最佳答案

RewriteEngine 将 domain.com 重定向到 www.domain.com 有点矫枉过正。这就是我用于我的 tomcat 安装的...您的 ajp 行也很好:

<VirtualHost *:80>
ServerName domain.com
Redirect / http://www.domain.com/
</VirtualHost>

<VirtualHost *:80>
ServerName www.domain.com
ProxyPass / http://www.domain.com:8080/
ProxyPassReverse / http://www.domain.com:8080/
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>

关于tomcat 前面的 apache 和重定向无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38213606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com