码头透明代理始终返回403禁止 [英] jetty transparent proxy always returns 403 forbidden

查看:99
本文介绍了码头透明代理始终返回403禁止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用码头提供的透明代理.

I am trying to use the transparent proxy provided by jetty.

这是我的web.xml

This is my web.xml

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="WebApp_9"
     version="2.4"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Archetype Created Web Application</display-name>

<servlet>
    <servlet-name>googleProxy</servlet-name>
    <servlet-class>org.eclipse.jetty.servlets.ProxyServlet$Transparent</servlet-class>
    <init-param>
        <param-name>ProxyTo</param-name>
        <param-value>http://www.google.com</param-value>
    </init-param>
    <init-param>
        <param-name>Prefix</param-name>
        <param-value>/google</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>googleProxy</servlet-name>
    <url-pattern>/google/*</url-pattern>
</servlet-mapping>

这是pom.xml(我正在使用maven):

and this is the pom.xml (I am using maven):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JettyProxySample</groupId>
<artifactId>JettyProxySample</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>JettyProxySample Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-servlets</artifactId>
        <version>7.0.0.M4</version>
    </dependency>
</dependencies>
<build>
    <finalName>JettyProxySample</finalName>
    <plugins>
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.10</version>
            <configuration>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <stopKey>foo</stopKey>
                <stopPort>9999</stopPort>
            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <scanIntervalSeconds>0</scanIntervalSeconds>
                        <daemon>true</daemon>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我希望代理转发这样的请求:

I expect the proxy to forward a request like this:

http://localhost:8080/JettyProxySample/google/search?q=hello

对此:

http://www.google.com/search?q=hello

但是当我在浏览器中尝试该URL时,我总是会得到这个信息:

But when I try that url in browser, I always get this:

HTTP ERROR: 403

FORBIDDEN
RequestURI=/JettyProxySample/google/search

Powered by Jetty://

有什么主意吗?

推荐答案

仅在此处给出一个答案,不要使用已有多年的里程碑版本.

Just to toss an answer onto here, do not use a milestone release that is years old.

  • jetty7的
  • 7.6.7.v20120910
  • jetty8的8.1.7.v20120910

我知道很多人都成功地在两个版本中使用了代理servlet,只是从最初的从codehaus到eclipse的迁移而已...那时候有大量的代码搅动,所以如果它出现了,我就不会感到惊讶这对您来说无法正常工作.

I know lots of folks using the proxy servlet in both versions successfully, just not something that was from the initial migrations from codehaus to eclipse...there was a serious amount of code churn back then so I would not be surprised if this isn't working correctly for you.

这篇关于码头透明代理始终返回403禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆