Project

General

Profile

[Solved] Invalid Charcter in lighttpd.conf "setenv.add-response-header"

Added by airsoftsoldrecn9 18 days ago

I am experiencing the following issue with in my lighttpd.conf file when attempting to configure a custom response header.

---------------------
source: /etc/lighttpd/lighttpd.conf line: 52 pos: 12 invalid character in variable name
2024-06-30 15:50:02: (../src/configfile.c.2288) configfile parser failed at: (

source: /etc/lighttpd/lighttpd.conf line: 51 pos: 38 invalid character in variable name
2024-06-30 15:58:00: (../src/configfile.c.2288) configfile parser failed at: (
---------------------

My lightpd.conf file:
---------------------

server.document-root = "/var/www/localhost/htdocs/someplace1" 

debug.log-request-handling   = "enable" 
debug.log-file-not-found     = "enable" 
debug.log-condition-handling = "enable" 

server.modules = (
                   "mod_setenv",
                   "mod_rewrite",
                   "mod_redirect",
                   "mod_access",
                   "mod_accesslog",
                   "mod_fastcgi",
                   "mod_cgi",
                   "mod_openssl",
                   "mod_simple_vhost" 
                 )

server.errorlog             = "/var/log/lighttpd/error.log" 
accesslog.filename          = "/var/log/lighttpd/access.log" 
#server.pid-file             = "/var/run/lighttpd.pid" 
#server.username             = "www-data" 
#server.groupname            = "www-data" 

$SERVER["socket"] == ":443" {
    ssl.engine = "enable" 
    ssl.pemfile = "/etc/ssl/default.pem" 

}

$SERVER["socket"] == ":80" { ssl.engine = "disable" }
#$SERVER["socket"] == "[::]:80" { ssl.engine = "disable" }

$HTTP["host"] =~ "someplace1.com" {
        server.document-root = "/var/www/localhost/htdocs/someplace1" 
         #server.errorlog = "/var/log/lighttpd/someplace1/error.log" 
         #accesslog.filename = "/var/log/lighttpd/someplace1/access.log" 
        ssl.pemfile = "/etc/ssl/someplace1/someplace1.org.pem" 
}

$HTTP["host"] =~ "^(.+\.)?someplace2.com" {
        server.document-root = "/var/www/localhost/htdocs/someplace2" 
         #server.errorlog = "/var/log/lighttpd/someplace2/error.log" 
         #accesslog.filename = "/var/log/lighttpd/someplace2/access.log" 
        ssl.pemfile = "/etc/ssl/daniyyels/someplace2.com.pem" 
        setenv.add-response-header += (“Access-Control-Allow-Origin” => “*”)
}

mimetype.assign = (
  ".html" => "text/html",
  ".htm" => "text/html",
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png",
  ".js"  => "text/javascript",
  ".css" => "text/css",
  ".svg" => "images/svg+xml" 
)

include "mod_fastcgi.conf" 

static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" )

index-file.names = ("index.php", "index.html")

--------------------------

Thank you for taking time to look at this issue!


Replies (4)

RE: Invalid Charcter in lighttpd.conf "setenv.add-response-header" - Added by airsoftsoldrecn9 18 days ago

Using a containerized (Docker) version of lighttpd on Ubuntu 22.04.4 LTS:
lighttpd/1.4.73 (ssl)

RE: Invalid Charcter in lighttpd.conf "setenv.add-response-header" - Added by flynn 18 days ago

The double quotes in the line

setenv.add-response-header += (“Access-Control-Allow-Origin” => “*”)

may look correct, but they are wrong.
Please use the correct double quotes:
setenv.add-response-header = ("Access-Control-Allow-Origin" => "*")

RE: Invalid Charcter in lighttpd.conf "setenv.add-response-header" - Added by airsoftsoldrecn9 16 days ago

Thank you! My apologies for overlooking such an obvious mistake; should not have used direct copy and paste.

As a follow-up question, which may be out of scope, I am trying to actually resolve the following issue when loading a particular Javascript add-on.

Access to script at '<blah>' from origin '<this site>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I am not sure if adding the response header "Access-Control-Allow-Origin" should actually resolve this CORS policy issue.

Any advice or direction is greatly appreciated!

RE: Invalid Charcter in lighttpd.conf "setenv.add-response-header" - Added by flynn 16 days ago

From my knowledge and experience
- adding the header Access-Control-Allow-Origin with value * was often propagated, but does not work anymore, because many browsers do not accept the generic value * anymore
- the correct behaviour is, that the request includes an Origin header with the url
- the server verifies this url and sends a Access-Control-Allow-Origin header with the allowed url(s)

I use a lua script using mod_magnet in lighttpd like this:

local r = lighty.r
local req_header = r.req_header

-- do not forget: replace the dummy hostnames ...
local allowed = { ["https://a.b.c.d"] = true, ["https://e.f.g.h"] = true }
local origin = req_header['Origin']
if allowed[origin] then
  local resp_header = r.resp_header
  resp_header["Access-Control-Allow-Origin"] = origin
  resp_header["Vary"] = "Origin" 
end

Limit the scope of the lua-script with $HTTP["url"] = { ... } and use magnet.attract-raw-url-to or magnet.attract-physical-path-to to activate it.

    (1-4/4)