-1

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.

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.

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

Preeti
  • 535
  • 1
  • 6
  • 30

1 Answers1

0

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.

gstrauss
  • 2,091
  • 1
  • 12
  • 16
  • Hello @gstrauss, thanks for the response. I am the "root" user and no other users are created. There was a running process on 81 and I killed it. Now doing `/etc/init.d/lighttpd start` shows `* Starting web server lighttpd`. But when I launch http://127.0.0.1:81 from browser, it shows `This site can’t be reached. localhost refused to connect.` – Preeti Apr 05 '22 at 14:09
  • 1
    As posted on https://redmine.lighttpd.net/boards/2/topics/10379, your problem is likely an issue with your understanding of containers and networking. Try running lighttpd on your local machine on port 81, but not inside a container. Then, learn how to configure and access services running inside a container. – gstrauss Apr 06 '22 at 15:15
  • Hello @gstrauss, yes running lighttpd outside container is working fine. The reason it's not working from docker container is by default when we create a container it's port will not be published to outside world unless we mention it via "-p" during container creation. But I was looking into other solutions where it's claimed that we can assign a port mapping to running container. It involves modifying `hostconfig.json` docker file as suggested in https://stackoverflow.com/questions/19335444/how-do-i-assign-a-port-mapping-to-an-existing-docker-container Any idea whether doing this be helpful? – Preeti Apr 06 '22 at 16:07
  • This post asks about lighttpd and has the tag 'lighttpd'. Yet your problem is your container configuration. Therefore, I am downvoting this question, as it is poorly stated and, until your comment above, failed to acknowledge that lighttpd works fine. Your problem is your container configuration. – gstrauss Apr 07 '22 at 18:14
  • Hello @gstrauss, I agree. I have corrected the docker configuration and now lighttpd is working fine. I have also posted update on https://redmine.lighttpd.net/boards/2/topics/10379?r=10386. Can you please check it? I will also update the relevant solution here. Can you please revoke the voting so that post won't get deleted. This might also be helpful to others who are working with docker and lighttpd. Thanks in advance. – Preeti Apr 07 '22 at 18:18
  • I think you should post a new better-worded question about configuring a docker container for lighttpd, and then post your answer. "How to properly configure lighttpd in Ubuntu?" remains poorly-worded for "Preeti did not properly configure the docker container". – gstrauss Apr 08 '22 at 19:14