简体   繁体   中英

How to properly configure lighttpd in Ubuntu?

Recently I started working with "lighttpd" webserver to host local webserver to place some files. I am using Ubuntu 20.04 machine within the docker container. I am following this guide lighttpd . I have installed lighttpd package using apt install lighttpd . The lighttpd.conf looks like:

server.modules = (
        "mod_indexfile",
        "mod_access",
        "mod_alias",
        "mod_redirect",
)

server.document-root        = "/var/www/html"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 81
server.bind                 = "localhost"
server.tag                  = "lighttpd"

# strict parsing and normalization of URL for consistency and security
# https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_http-parseoptsDetails
# (might need to explicitly set "url-path-2f-decode" = "disable"
#  if a specific application is encoding URLs inside url-path)
server.http-parseopts = (
  "header-strict"           => "enable",# default
  "host-strict"             => "enable",# default
  "host-normalize"          => "enable",# default
  "url-normalize-unreserved"=> "enable",# recommended highly
  "url-normalize-required"  => "enable",# recommended
  "url-ctrls-reject"        => "enable",# recommended
  "url-path-2f-decode"      => "enable",# recommended highly (unless breaks app)
 #"url-path-2f-reject"      => "enable",
  "url-path-dotseg-remove"  => "enable",# recommended highly (unless breaks app)
 #"url-path-dotseg-reject"  => "enable",
 #"url-query-20-plus"       => "enable",# consistency in query string
)

index-file.names            = ( "index.php", "index.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.conf.pl"
include "/etc/lighttpd/conf-enabled/*.conf"

#server.compat-module-load   = "disable"
server.modules += (
        "mod_compress",
        "mod_dirlisting",
        "mod_staticfile",
)

Also I have a simple HTML file in /var/www/html/ to display Hello World!

But when I start lighttpd using /etc/init.d/lighttpd start I get:

(network.c.311) can't bind to socket: 127.0.0.1:81 Address already in use

And when I open browser (ex, chrome) and launch localhost:81 , it shows This site can't be reached. localhost refused to connect. This site can't be reached. localhost refused to connect.

I tried with /etc/init.d/lighttpd stop and started again but it results in the same error.

When I do netstat -ntulp :

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:81            0.0.0.0:*               LISTEN      -

I expected a PID should have been assigned to lighttpd

Can anyone please let me know what is the issue here and how can it be resolved?

Update

This is not the issue with lighttpd . This happens when docker container is not properly configured. By default ports are not allowed when we create conatiner. We need to allow port forwarding when we create container using option -p along with docker create or docker run . Further info can be found in docker documentation:container.networking

Thanks in advance.

PS: Please let me know if any info is missing here.

The output you shared suggests that some process is still running and listening on port 81.

As root run netstat -ntulp to find the pid and have the process name listed. You can also list the processes running as user www-data with ps -u www-data . You probably want to kill the pid to whatever process is listening on 81.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM