[Twisted-Python] Proxy server in front of two web sites
![](https://secure.gravatar.com/avatar/fb7e7f9ebeb656f0d94992f5f115764a.jpg?s=120&d=mm&r=g)
I'm looking at implementing a solution for the following problem: I have a setup with two web servers. Each contains the same directory structure but not the same files. Using a proxy server in front of these two I would like to merge them into one. So the proxy would first hit server A and if A returned a 404 then it would hit B. Is this something that I should implement as a web server or as a proxy server? Is there actually a difference? S.
![](https://secure.gravatar.com/avatar/4e1ae4b836a9cfe3945d8c661b37246b.jpg?s=120&d=mm&r=g)
Stefan Arentz ha scritto:
You can use Nginx for this. Sample configuration (not tested): upstream backend { server backend1.example.com weight=1; server backend2.example.com:8080 weight=0; } server { location / { proxy_next_upstream http_404; proxy_pass http://backend; } } Regards Manlio Perillo
![](https://secure.gravatar.com/avatar/e134a7c1546bb254d8fee3eb90cfa235.jpg?s=120&d=mm&r=g)
"Stefan Arentz" <stefan.arentz@gmail.com> writes:
Well, de facto it will (almost-*) always be a proxy, proxy is something that forwards requests and responses. One thing to note is that if you want backend servers to see the client IP, some extra effort is needed (like mod_rpaf on backend and adding X-Forwarded-For on proxy). nginx suggestion is good one, although of course not the only possible. I believe almost every product suitable to work as reverse-proxy should handle this use case. *) There exists the solution which does not require a proxy (and is reasonable if most of the requests go to the first server). Just have clients accessing the first server but in error handler redirect them to the second server whenever they face 404. This way one item less to manage. But such process will not be transparent for users, they will see different URLs.
![](https://secure.gravatar.com/avatar/fb7e7f9ebeb656f0d94992f5f115764a.jpg?s=120&d=mm&r=g)
The problem is that I don't have control over these servers. Otherwise I would have implemented the redirect. I've done a quick hack where I have a Resource that deals with this directory hierarchy and simply starts a client.getPage to retrieve the page and does a redirect if it does not exist. It works fairly well, initial tests with 'ab' gives really reasonable performance actually. Without any optimization or caching :-) S. On 10/29/07, Marcin Kasperski <Marcin.Kasperski@softax.com.pl> wrote:
![](https://secure.gravatar.com/avatar/4e1ae4b836a9cfe3945d8c661b37246b.jpg?s=120&d=mm&r=g)
Stefan Arentz ha scritto:
You can use Nginx for this. Sample configuration (not tested): upstream backend { server backend1.example.com weight=1; server backend2.example.com:8080 weight=0; } server { location / { proxy_next_upstream http_404; proxy_pass http://backend; } } Regards Manlio Perillo
![](https://secure.gravatar.com/avatar/e134a7c1546bb254d8fee3eb90cfa235.jpg?s=120&d=mm&r=g)
"Stefan Arentz" <stefan.arentz@gmail.com> writes:
Well, de facto it will (almost-*) always be a proxy, proxy is something that forwards requests and responses. One thing to note is that if you want backend servers to see the client IP, some extra effort is needed (like mod_rpaf on backend and adding X-Forwarded-For on proxy). nginx suggestion is good one, although of course not the only possible. I believe almost every product suitable to work as reverse-proxy should handle this use case. *) There exists the solution which does not require a proxy (and is reasonable if most of the requests go to the first server). Just have clients accessing the first server but in error handler redirect them to the second server whenever they face 404. This way one item less to manage. But such process will not be transparent for users, they will see different URLs.
![](https://secure.gravatar.com/avatar/fb7e7f9ebeb656f0d94992f5f115764a.jpg?s=120&d=mm&r=g)
The problem is that I don't have control over these servers. Otherwise I would have implemented the redirect. I've done a quick hack where I have a Resource that deals with this directory hierarchy and simply starts a client.getPage to retrieve the page and does a redirect if it does not exist. It works fairly well, initial tests with 'ab' gives really reasonable performance actually. Without any optimization or caching :-) S. On 10/29/07, Marcin Kasperski <Marcin.Kasperski@softax.com.pl> wrote:
participants (3)
-
Manlio Perillo
-
Marcin Kasperski
-
Stefan Arentz