Lighttpd installing and configuring

Install

sudo apt-get install lighttpd

Config place

/etc/lighttpd/lighttpd.conf

www-root and main settings

server.document-root        = "/var/www/html"
server.upload-dirs          = ("/var/cache/lighttpd/uploads" )
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80

#need mod_access!
url.access-deny             = ( "~", ".inc" ) 

Server compression (after lighttpd 1.4.42)

Enable compression mod:

server.modules = (          
        ...
        "mod_deflate",     
       ...
)                           
#deflate.mimetypes = ("text/")       # prefix matches all text/* Content-Type responses
deflate.mimetypes = ("text/html", "text/plain", "text/css", "text/javascript", "text/xml")
deflate.allowed-encodings = ( "br", "gzip", "deflate" ) # "bzip2" and "zstd" also supported

## optional

deflate.cache-dir = "/path/to/compress/cache" 

See also: https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModDeflate

Server compression (before lighttpd 1.4.42)

Enable compression mod:

server.modules = (          
        ...
        "mod_compress",     
       ...
)                           

Configure content types for compression:

compress.allowed-encodings = ("bzip2", "gzip", "deflate")                                                   
compress.cache-dir = "/var/cache/lighttpd/compress"                                                         
compress.filetype = ("application/javascript", "application/json", "application/octet-stream", "text/plain")

Virtual hosts and access logs

Enable mods:

server.modules = (          
        ...
        "mod_accesslog",     
       ...
)   

Then, configure virtual host and logs:

$HTTP["host"] == "www.sample.com" {                            
server.document-root  =       "/var/www/html/sample"
server.errorlog             =       "/var/log/lighttpd/sample-error.log"           
accesslog.filename       =       "/var/log/lighttpd/sample-access.log"  
}                                                                       

Simple auth

  1. Enable auth module:
server.modules = (          
        ...
        "mod_auth",     
       ...
)      
...
auth.debug = 2                                                      
auth.backend = "plain"                                              
auth.backend.plain.userfile = "/home/vdsuser/.lighttpdpassword"                        
  1. Create password-file:
root@myhost:/home/vdsuser# cat ./.lighttpdpassword
user1:userpassword
  1. Add to virtual host config:
$HTTP["host"] == "auth.sample.com" {                
...
auth.require = ("/" =>                                     
(                                                          
"method" => "basic",                                       
"realm" => "Password needed here",                         
"require" => "user=user1"
))                                                         
}                                                          

Reverse proxy

Enable mods:

server.modules = (          
        ...
        "mod_proxy",     
       ...
)   

Then, configure:

# geoserver proxy                                                
$HTTP["host"] == "geoserver.sample.com" {
 proxy.server = ("" => ( (                                       
 "host" => "127.0.0.1",                                          
 "port" => 8600 ) ) )                                            
 accesslog.filename = "/var/log/lighttpd/geoserver-access.log"   
}                                                                

HTTPS

$SERVER["socket"] == ":443" {                                              
        ssl.engine = "enable"                                              
        ssl.pemfile = "/etc/letsencrypt/live/sample.com/pemfile.pem"  
        ssl.ca-file = "/etc/letsencrypt/live/sample.com/fullchain.pem"
        server.name = "*.sample.com"
    }                                                                      

In new versions need enable mod:

...
 "mod_openssl",
...

See also

Publish Asp.Net Core App to Linux

Letsencrypt cert update


Создано: 12/10/2021 12:57, Изменено: 11/11/2021 11:12, Просмотров: 46
Назад