[Libwebsockets] How to set vhost url?

Andy Green andy at warmcat.com
Wed Jul 24 16:48:02 CEST 2019



On 7/24/19 7:34 AM, necktwi wrote:

> I am porting my server from 2.x to 3.1. Previously I've implemented vhosts by parsing the request header and serve the respective file path with lws_plat_file_x functions. Now in 3.1 there are no lws_plat_file_x functions.
> How to specify
> host1.mydomain.com to server /var/www/host1
> or
> host2.mydomain.com to serve /var/www/host2?
> 
> does
> 
> vhost1_lws_http_mount .mountpoint = "host1.mydomain.com"
> vhost1_lws_http_mount .origin = "/var/www/host1"
> vhost2_lws_http_mount .mountpoint = "host2.mydomain.com"
> vhost2_lws_http_mount .origin = "/var/www/host2"
> 
> does the trick?

No, but you half have the right idea already.

There isn't any "vhost url".  One vhost can have as many mounts as you 
need to apply different things into its url space.  For example on 
libwebsockets.org, if you go to / it has the usual fileserving mount 
like you discuss.  If you go to /git, it matches a different mount that 
proxies through to a gitohashi daemon over a unix domain socket.

When you create the vhost, you can each time set info.mount to the 
mounts you want to apply.  Eg look at

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/http-server/minimal-http-server-multivhost/minimal-http-server.c

It creates 3 x vhost each with a different mount telling it to serve 
that vhost's / from different places in the filesystem.

-Andy

> ... Necktwi
> 
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets
> 


More information about the Libwebsockets mailing list