[Solved] Example of mod_simple_vhost implemention using lua fails
I was trying to set up a customized vhost system using mod_magnet
and lua, but I couldn't get it to work. To troubleshoot my issue, I decided to try the basic mod_simple_vhost code from the ModMagnetExamples page, but that seems to fail with the exact same error. Here's the error log of the request I'm making:
2023-07-14 14:46:51: (../src/h1.c.497) fd:10 rqst: GET /post/ HTTP/1.1 2023-07-14 14:46:51: (../src/h1.c.497) fd:10 rqst: Host: localhost:8000 2023-07-14 14:46:51: (../src/h1.c.497) fd:10 rqst: User-Agent: curl/8.1.2 2023-07-14 14:46:51: (../src/h1.c.497) fd:10 rqst: Accept: */* 2023-07-14 14:46:51: (../src/h1.c.497) fd:10 rqst: 2023-07-14 14:46:51: (../src/response.c.260) -- parsed Request-URI 2023-07-14 14:46:51: (../src/response.c.262) Request-URI : /post/ 2023-07-14 14:46:51: (../src/response.c.264) URI-scheme : http 2023-07-14 14:46:51: (../src/response.c.266) URI-authority : localhost:8000 2023-07-14 14:46:51: (../src/response.c.268) URI-path (clean): /post/ 2023-07-14 14:46:51: (../src/response.c.270) URI-query : 2023-07-14 14:46:51: (../src/mod_magnet.c.3245) lua: [string "/opt/lighttpd_experiment/handlers/simple..."]:18: couldn't store 'physical.doc_root' in r.req_attr[] 2023-07-14 14:46:51: (../src/mod_magnet.c.3245) lua: stack traceback: 2023-07-14 14:46:51: (../src/mod_magnet.c.3245) lua: \t[C]: in metamethod 'newindex' 2023-07-14 14:46:51: (../src/mod_magnet.c.3245) lua: \t[string "/opt/lighttpd_experiment/handlers/simple..."]:18: in main chunk 2023-07-14 14:46:51: (../src/h1.c.248) fd:10 resp: HTTP/1.1 500 Internal Server Error 2023-07-14 14:46:51: (../src/h1.c.248) fd:10 resp: Content-Type: text/html 2023-07-14 14:46:51: (../src/h1.c.248) fd:10 resp: Content-Length: 365 2023-07-14 14:46:51: (../src/h1.c.248) fd:10 resp: Date: Fri, 14 Jul 2023 12:46:51 GMT 2023-07-14 14:46:51: (../src/h1.c.248) fd:10 resp: Server: lighttpd/1.4.71 2023-07-14 14:46:51: (../src/h1.c.248) fd:10 resp:
And here's is the entire config file I'm using. As you can see, the simple_vhost
script is the first of several lua scripts to run on the attract-raw-url-to
phase, but apart from that nothing particularly special is going on.
# {{{ variables var.basedir = env.LIGHTTPD_BASEDIR var.magnetdir = var.basedir + "/handlers" var.statedir = var.basedir + "/state" var.logdir = var.statedir + "/log" # }}} # {{{ modules # At the very least, mod_access and mod_accesslog should be enabled. # All other modules should only be loaded if necessary. # NOTE: the order of modules is important. server.modules = ( "mod_rewrite", # "mod_redirect", # "mod_alias", "mod_access", # "mod_auth", # "mod_status", # "mod_setenv", # "mod_proxy", # "mod_simple_vhost", # "mod_evhost", # "mod_userdir", # "mod_deflate", # "mod_ssi", # "mod_expire", # "mod_rrdtool", # "mod_webdav", "mod_accesslog", "mod_magnet" ) # }}} # {{{ includes include "mimetypes.conf" # }}} # {{{ server settings #server.username = "lighttpd" #server.groupname = "lighttpd" server.port = env.LIGHTTPD_PORT server.document-root = "/dev/null" server.pid-file = var.statedir + "/lighttpd.pid" server.errorlog = var.logdir + "/error.log" # error-handler for status 404 # server.error-handler-404 = "/error-handler.html" # server.error-handler-404 = "/error-handler.php" # Format: <errorfile-prefix><status-code>.html # -> ..../status-404.html for 'File not found' # server.errorfile-prefix = var.basedir + "/error/status-" index-file.names = ("index.html") # {{{ mod_staticfile # which extensions should not be handled via static-file transfer # (extensions that are usually handled by mod_cgi, mod_fastcgi, etc). static-file.exclude-extensions = (".php", ".pl", ".cgi", ".fcgi") # }}} # {{{ mod_accesslog accesslog.filename = var.logdir + "/access.log" # }}} # {{{ mod_access # see access.txt url.access-deny = ("~", ".inc") # }}} # {{{ extra rules magnet.attract-raw-url-to = ( var.magnetdir + "/simple_vhost.lua", var.magnetdir + "/activity.lua" ) # Handle Webfinger requests $HTTP["url"] == "/.well-known/webfinger" { magnet.attract-raw-url-to = (var.magnetdir + "/webfinger.lua") } # Handle posts to inbox $HTTP["url"] == "/inbox" { $HTTP["request-method"] == "POST" { magnet.attract-raw-url-to = (var.magnetdir + "/inbox.lua") } } # }}} # {{{ debug debug.log-request-header = "enable" debug.log-response-header = "enable" debug.log-request-handling = "enable" debug.log-file-not-found = "enable" # }}}
Replies (2)
RE: Example of mod_simple_vhost implemention using lua fails - Added by gstrauss 3 months ago
The mod_magnet documentation is correct. It should be lighty.r.req_attr["physical.doc-root"]
The examples on the wiki page should use physical.doc-root
instead of (incorrect) physical.doc_root
. The examples wiki page will be updated momentarily.
RE: Example of mod_simple_vhost implemention using lua fails - Added by brecht 3 months ago
Good spot, I hadn't noticed the difference between those two places. It works as expected now.
For reference, just in case someone stumbles on this thread in the future, I did also have to adapt my config to have the vhost script run on attract-physical-path-to
instead of attract-raw-url-to
. The mod_magnet section looks like this now:
magnet.attract-physical-path-to = (var.magnetdir + "/vhost.lua") magnet.attract-raw-url-to = (var.magnetdir + "/activity.lua") # Handle Webfinger requests $HTTP["url"] == "/.well-known/webfinger" { magnet.attract-raw-url-to = (var.magnetdir + "/webfinger.lua") } # Handle posts to inbox $HTTP["url"] == "/inbox" { $HTTP["request-method"] == "POST" { magnet.attract-raw-url-to = (var.magnetdir + "/inbox.lua") } }