Darkhttpd: Difference between revisions
Ginjachris (talk | contribs) m (→Use) |
(prefix commands with $ or #) |
||
(9 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:darkhttpd}} | |||
darkhttpd is a simple, fast HTTP 1.1 web server for static content. It does not support PHP or CGI etc but is designed to serve static content, which it does very well. darkhttpd would be an excellent alternative to [[Lighttpd]] for [[How to setup a Alpine Linux mirror|running an Alpine mirror]] | |||
For a full list of features see the [https://unix4lyfe.org/darkhttpd/ darkhttpd homepage] | |||
For a full list of features see the [ | |||
= Install = | = Install = | ||
{{Cmd|apk add darkhttpd}} | {{Cmd|# apk add darkhttpd}} | ||
= Configure = | = Configure = | ||
Line 16: | Line 16: | ||
There's no configuration file for {{Pkg|darkhttpd}}, everything is controlled from the command line or in our case the OpenRC init file, which is stored in {{Path|/etc/init.d/darkhttpd}} and by default looks like this: | There's no configuration file for {{Pkg|darkhttpd}}, everything is controlled from the command line or in our case the OpenRC init file, which is stored in {{Path|/etc/init.d/darkhttpd}} and by default looks like this: | ||
< | {{cat|/etc/init.d/darkhttpd|<nowiki>#!/sbin/runscript | ||
#! /sbin/runscript | |||
description="darkhttpd web server" | description="darkhttpd web server" | ||
Line 25: | Line 24: | ||
pidfile="" | pidfile="" | ||
stopsig="SIGTERM" | stopsig="SIGTERM" | ||
</ | </nowiki>}} | ||
So by default we will serve pages from {{Path|/var/www/localhost/htdocs}} and darkhttpd will run as a background daemon, [https://en.wikipedia.org/wiki/Chroot chrooted] to {{Path|/var/www/localhost/htdocs}} with a user of <code>darkhttpd</code> and group of <code>www-data</code>. | So by default we will serve pages from {{Path|/var/www/localhost/htdocs}} and darkhttpd will run as a background daemon, [https://en.wikipedia.org/wiki/Chroot chrooted] to {{Path|/var/www/localhost/htdocs}} with a user of <code>darkhttpd</code> and group of <code>www-data</code>. | ||
Line 33: | Line 32: | ||
Change any of these values as you see fit, but it's a good idea to backup the file before making changes. | Change any of these values as you see fit, but it's a good idea to backup the file before making changes. | ||
For a full list of available options, run: {{Cmd|darkhttpd}} | For a full list of available options, run: {{Cmd|$ darkhttpd}} | ||
and amend the <code>command_args</code> line as you see fit. | and amend the <code>command_args</code> line as you see fit. | ||
For example, you might wish to serve files from {{Path|/var/files}} instead, so you can edit the {{Path|/etc/init.d/darkhttpd}} file with an editor of your choice (vi, nano, vim or whatever) and make it like so: | For example, you might wish to serve files from {{Path|/var/files}} instead, so you can edit the {{Path|/etc/init.d/darkhttpd}} file with an editor of your choice (vi, nano, vim or whatever) and make it like so: | ||
< | {{cat|/etc/init.d/darkhttpd|<nowiki>#!/sbin/runscript | ||
#! /sbin/runscript | |||
description="darkhttpd web server" | description="darkhttpd web server" | ||
Line 47: | Line 45: | ||
pidfile="" | pidfile="" | ||
stopsig="SIGTERM" | stopsig="SIGTERM" | ||
</ | </nowiki>}} | ||
= Use = | = Use = | ||
Filesharing is made easy; simply add your files under the server root, by default {{Path|/var/www/localhost/ | Filesharing is made easy; simply add your files under the server root, by default {{Path|/var/www/localhost/htdocs}} | ||
== Test == | == Test == | ||
Create a test page under the server root, by default {{Path|/var/www/localhost/ | Create a test page under the server root, by default {{Path|/var/www/localhost/htdocs}} | ||
{{Cmd|echo "this is a test page" > /var/www/localhost/htdocs/index.html}} | {{Cmd|# echo "this is a test page" > /var/www/localhost/htdocs/index.html}} | ||
{{Note| You don't have to create a test page; in a working environment darkhttpd will generate a directory listing if no index page is found.}} | {{Note| You don't have to create a test page; in a working environment darkhttpd will generate a directory listing if no index page is found.}} | ||
Start the daemon: {{Cmd|rc-service darkhttpd start}} | Start the daemon: {{Cmd|# rc-service darkhttpd start}} | ||
Output should be something like this: | Output should be something like this: | ||
Line 75: | Line 72: | ||
Now point a browser to your darkhttpd server and you should get the index page, or a directory listing if you didn't create an index page. | Now point a browser to your darkhttpd server and you should get the index page, or a directory listing if you didn't create an index page. | ||
Check the logfile: {{Cmd|tail /var/log/darkhttpd/access.log}} | Check the logfile: {{Cmd|$ tail /var/log/darkhttpd/access.log}} | ||
== Controlling darkhttpd status == | == Controlling darkhttpd status == | ||
Stop, start and restart the daemon in the usual fashion: | Stop, start and restart the daemon in the usual fashion: | ||
{{Cmd|rc-service darkhttpd start}} | {{Cmd|# rc-service darkhttpd start}} | ||
{{Cmd|rc-service darkhttpd stop}} | {{Cmd|# rc-service darkhttpd stop}} | ||
{{Cmd|rc-service darkhttpd restart}} | {{Cmd|# rc-service darkhttpd restart}} | ||
== Auto-start darkhttpd at boot == | == Auto-start darkhttpd at boot == | ||
To add the daemon to the default runlevel so it auto-starts at boot, do: {{Cmd|rc-update add darkhttpd}} | To add the daemon to the default runlevel so it auto-starts at boot, do: {{Cmd|# rc-update add darkhttpd}} | ||
= Troubleshooting = | = Troubleshooting = | ||
Line 103: | Line 100: | ||
* If the daemon will not start, ensure you haven't made a syntax error in the init script. | * If the daemon will not start, ensure you haven't made a syntax error in the init script. | ||
* Ensure the daemon is running with {{Cmd|rc-status}} | * Ensure the daemon is running with {{Cmd|$ rc-status}} | ||
* Make use of the logs to check it is receiving requests. To do this, run {{Cmd|tail -f /var/log/darkhttpd/access.log}} and then send requests to the web server. If darkhttpd is receiving the requests, lines will be logged. If you don't see these lines, perhaps a firewall rule is blocking access to the server or there is a routing issue somewhere? | * Make use of the logs to check it is receiving requests. To do this, run {{Cmd|$ tail -f /var/log/darkhttpd/access.log}} and then send requests to the web server. If darkhttpd is receiving the requests, lines will be logged. If you don't see these lines, perhaps a firewall rule is blocking access to the server or there is a routing issue somewhere? | ||
Use | Use {{key|Ctrl}}+{{key|C}} to exit back to the prompt when finished testing. | ||
= | = See also = | ||
< | * <code>darkhttpd --help</code> | ||
</ | |||
[[Category:Server]] | [[Category:Web Server]] |
Latest revision as of 07:36, 26 September 2023
darkhttpd is a simple, fast HTTP 1.1 web server for static content. It does not support PHP or CGI etc but is designed to serve static content, which it does very well. darkhttpd would be an excellent alternative to Lighttpd for running an Alpine mirror
For a full list of features see the darkhttpd homepage
Install
# apk add darkhttpd
Configure
Default location of files to serve: /var/www/localhost/htdocs
Default log path: /var/log/darkhttpd/access.log
There's no configuration file for darkhttpd, everything is controlled from the command line or in our case the OpenRC init file, which is stored in /etc/init.d/darkhttpd and by default looks like this:
Contents of /etc/init.d/darkhttpd
So by default we will serve pages from /var/www/localhost/htdocs and darkhttpd will run as a background daemon, chrooted to /var/www/localhost/htdocs with a user of darkhttpd
and group of www-data
.
Logs will go to /var/log/darkhttpd/access.log.
The default values have been chosen to provide sane, secure settings.
Change any of these values as you see fit, but it's a good idea to backup the file before making changes.
For a full list of available options, run:
$ darkhttpd
and amend the command_args
line as you see fit.
For example, you might wish to serve files from /var/files instead, so you can edit the /etc/init.d/darkhttpd file with an editor of your choice (vi, nano, vim or whatever) and make it like so:
Contents of /etc/init.d/darkhttpd
Use
Filesharing is made easy; simply add your files under the server root, by default /var/www/localhost/htdocs
Test
Create a test page under the server root, by default /var/www/localhost/htdocs
# echo "this is a test page" > /var/www/localhost/htdocs/index.html
Start the daemon:
# rc-service darkhttpd start
Output should be something like this:
* Starting darkhttpd ... darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic. listening on: http://0.0.0.0:80/ chrooted to `/var/www/localhost/htdocs' set gid to 82 set uid to 100
Now point a browser to your darkhttpd server and you should get the index page, or a directory listing if you didn't create an index page.
Check the logfile:
$ tail /var/log/darkhttpd/access.log
Controlling darkhttpd status
Stop, start and restart the daemon in the usual fashion:
# rc-service darkhttpd start
# rc-service darkhttpd stop
# rc-service darkhttpd restart
Auto-start darkhttpd at boot
To add the daemon to the default runlevel so it auto-starts at boot, do:
# rc-update add darkhttpd
Troubleshooting
- When restarting the daemon you may see an error message:
Stopping darkhttpd ... /lib/rc/sh/runscript.sh: line 202: can't create /sys/fs/cgroup/openrc/darkhttpd/tasks: nonexistent directory Starting darkhttpd ...
This error message appears to be benign and of no consequence so can be ignored. I can only replicate this error on a VMWare vSphere client.
- If the daemon will not start, ensure you haven't made a syntax error in the init script.
- Ensure the daemon is running with
$ rc-status
- Make use of the logs to check it is receiving requests. To do this, run
$ tail -f /var/log/darkhttpd/access.log
and then send requests to the web server. If darkhttpd is receiving the requests, lines will be logged. If you don't see these lines, perhaps a firewall rule is blocking access to the server or there is a routing issue somewhere?
Use Ctrl+C to exit back to the prompt when finished testing.
See also
darkhttpd --help