Project

General

Profile

Reverse Proxy

Added by bp20200711 almost 4 years ago

I wrote a small system in Perl Mojolicious and want to add this to my website. There are several ways. One option is to start it with Hypnotoad. This uses port 8080. This works but it is better to integrate it into Lighttpd and for this I need to define a reverse proxy. While I read the documentation I didn't get this working.
Here is the configuration file:

proxy.debug = 65535

$HTTP["host"] == "192.168.15.3" {

# all extensions, 'css' is the optional label
proxy.server = ("" => 
                  ("" => 
                      ( "host" => "192.168.15.3",  
                        "port" => 8080
                      )
                  )
               )

proxy.header = ( 
                 "map_urlpath" => ( "/*)" => "/home/int/www/css/" ), 
                 "connect" => "enable",
               )


The server.document is '/home/int/www'; I'd like to show the Perl system at /home/int/www/css.
Hypnotoad is serving port 8080, lighttpd the standard 80.
I'm running lighttpd 1.4.55 on Debian.

Checked access log and error log but didn't find any entries of the proxy module but server-config shows me that mod-proxy has been activated.

BTW, I put a link into the lighttpd page: <a href="http://192.168.15.3:8080&quot;/target=&quot;_blank&quot;&gt;CSS System<a>

which links to the perl system without problems. But I'd like to get this fully integrated.
I would appreciate if you could help me to get this working.
Thanks and best regards,
Bernd


Replies (10)

RE: Reverse Proxy - Added by gstrauss almost 4 years ago

"map_urlpath" => ( "/*)" => "/home/int/www/css/" ),

  • The keyword is "map-urlpath" not "map_urlpath". Please be more careful.
  • A url-path is not a filesystem path. map-urlpath maps url-paths, as the name explicitly indicates.
  • "map-urlpath" does not operate on regexes (and there are no examples which use a regex, so I am not sure why you assumed that syntax)
  • I also have no idea what you aim with what looks to be invalid regex syntax: "/*)"

Please review the documentation for mod_proxy

You seem to intentionally set up proxy.server to be a reverse proxy for the entire site. If that read is correct, I do not understand why you think you need map-urlpath. However, that is a mismatch with your statement that the site is at /home/int/www and the css is at /home/int/www/css.

Due to the conflicting asks in your description, I am guessing with the following:
If you want lighttpd to serve your site / at /home/int/www, and to reverse proxy /css to Hypnotoad,

proxy.server = ("/css" => 
                  ("" => 
                      ( "host" => "192.168.15.3",  
                        "port" => 8080
                      )
                  )
               )

If (and only if) you need to map the url-path for Hypnotoad, then to map /css to / for Hypnotoad:
proxy.header = ( 
                 "map-urlpath" => ( "/css/" => "/" ), 
                 "connect" => "enable",
               )

RE: Reverse Proxy - Added by bp20200711 almost 4 years ago

Thank your very much for your advise.
I tried this but I'm still not getting anywhere. One thing which bothers me is that I don't see any mod_proxy entries in the error log (enabled all error types (debug.log-request-header = "enable",etc) and set proxy.debug = 65535.
What is the easiest way to get some proxy debug messages?

command hypnotoad ./script/my_app.pl starts the server and presents it at the ip address set in the configuration file e.g. "listen => ['http://192.168.15.3:8080']"

Apparently this is the same ip address as for lighttpd; I could set this to 127.0.0.1 ...

Lighttpd is at 192.168.15.3 and the server document is "/home/int/www" and there are a bunch of documents in that directory.

The perl site should be linked to the (/home/int/www)/css subdirectory. Currently I get a 200 message if that sub directory exists (system just shows the subdirectory) and 404 if I remove it.

As I don't see any proxy debug messages I think that something is completely wrong. Could you guide me to "the most simple setup"? That would help me to understand where the problem is.

Thanks and best regards

RE: Reverse Proxy - Added by gstrauss almost 4 years ago

Could you guide me to "the most simple setup"?

It sounds like you have not loaded mod_proxy
server.modules += ("mod_proxy")

Have you looked at the trace when lighttpd starts up? lighttpd will warn about unrecognized directives proxy.server and proxy.header if you do not load mod_proxy.

Please review the lighttpd documentation and how to ask a good technical question so that I don't continue guessing at what you are doing
How to get support - please read

lighttpd -h

RE: Reverse Proxy - Added by bp20200711 almost 4 years ago

"It sounds like you have not loaded mod_proxy" ...
I'm using Debian where you have not only one config file but also a config directory. This way you can have different configuration for different web sites.

But you're right I also thought mod_proxy might not have been enabled. Today I did some additional tests using just one config file.
I also run strace which told me:

openat(AT_FDCWD, "/usr/lib/lighttpd/mod_proxy.so", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\"\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=26464, ...}) = 0
mmap(NULL, 28688, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f88a62c5000
mmap(0x7f88a62c7000, 12288, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f88a62c7000
mmap(0x7f88a62ca000, 4096, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x5000) = 0x7f88a62ca000
mmap(0x7f88a62cb000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x5000) = 0x7f88a62cb000
close(3)     

But that is the only occasion...

Actually, I have been using lighttpd for well over 10 years - and it bothers me that the reverse proxy is not working. I see no messages in the access or error log. "strace" mentions mod_proxy just once.
This looks strange to me. And therefore I'm asking you if there any messages which "should be showing" .. either if everything is ok or if there are errors.

If you should have a "basic test case" then please let me know. If that is not working then either other config is interfering or the issue is related to the Debian setup.
Best regards

RE: Reverse Proxy - Added by gstrauss almost 4 years ago

How to get support - please read

You have posted multiple times, but have yet to post the version of Debian you are using, the version of lighttpd you are using, and your config.

You obviously have not read How to get support - please read
I strongly recommend starting there before posting further.

[Edit: apologies: you did post that you were using lighttpd 1.4.55]

RE: Reverse Proxy - Added by bp20200711 almost 4 years ago

I know that I reply to myself ...

Went back to square 1 and got this working with a simple file:

$HTTP["host"] == "192.168.15.3" {

# all extensions, 'css' is the optional label
proxy.server = ("" =>
                  ("" =>
                      ( "host" => "127.0.0.1",
                        "port" => 8080
                      )
                  )
               )

This show the perl system at 127.0.0.1 at the document root.
I'd like to show this at the <doc root>/css directory and tried:
proxy.header = ( 
                 "map-urlpath" => ( "" => "/css" ), 
                 "connect" => "enable",
               )

but this is not working. I also tried some variations like "/" => '/css" but this didn't work. Can you advise on this?
Thanks and best regards

RE: Reverse Proxy - Added by gstrauss almost 4 years ago

Please more carefully re-read the answers I already gave and look for what you misread and did differently.

RE: Reverse Proxy - Added by bp20200711 almost 4 years ago

Finally, the working version is:

# use 127.0.0.1 - 'host ip' and 'proxy id' can't be the same
# this statement shows the proxy at http://192.168.15.3 
proxy.server = ("" =>
                  ("" =>
                      ( "host" => "127.0.0.1",
                        "port" => 8080
                      )
                  )
               )

# need to show the proxy site not at 192.168.15.3 but at a subdirectory
# first: subdir you want to use, then the actual subdir of the proxy site
proxy.header = (
                 "map-urlpath" => ( "/css" => "/" )
            )

}

# Notes:
# if document root is http://192.168.15.3 either document root file OR
# the proxy content will show depending on which is defined first.
# To prevent this you need to define a different subdir via the proxy.header

Warum bekomme ich den Eindruck, dass manche sich immer verletzt fuehlen, wenn jemand Probleme hat. Man kann das Ganze doch auch mit ein paar funtionierenden Beispielen demonstrieren. Wer eine Loesung fuer sein Problem bekommt, wird Lighttpd auch benutzen. Wer nur gesagt bekommt, dass er die Dokumentation lesen soll und ersteinmal lernen soll, 'richtig' zu fragen, wird zur Konkurrenz gehen.

RE: Reverse Proxy - Added by gstrauss almost 4 years ago

We are volunteers. I am not sure why you think this is a competition with "others". You came here asking for (free) support and did not help those trying to help you. Also, you were not asked to read reams of documentation. You were asked to look a few comments up, on this page, to review the answer already given to you almost three days ago.

RE: Reverse Proxy - Added by bp20200711 almost 4 years ago

Hm, I appreciate any help and I didn't mean to hurt anybody - and I realize that you do voluntary work. Just forget my comments if you don't like them.

    (1-10/10)