← 返回命令列表

Linux command

darkhttpd 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Serve the current directory

darkhttpd .

Serve a specific directory

darkhttpd [/path/to/webroot] --port [8080]

Bind to a specific address

darkhttpd . --addr [127.0.0.1]

Set a custom index file

darkhttpd . --index [home.html]

Disable directory listing

darkhttpd . --no-listing

Serve with logging

darkhttpd . --log -

Serve with virtual hosting

darkhttpd . --forward [example.com] [http://backend:8000]

Run as a daemon

darkhttpd . --daemon --pidfile [/var/run/darkhttpd.pid]

说明

darkhttpd is a simple, fast, and secure static web server. Written in C with no dependencies, it compiles to a single small binary that can serve static files with minimal resource usage. The server is designed for simplicity: it serves files from a document root directory with proper MIME types, handles HTTP/1.1 keep-alive connections, and supports security features like chroot and privilege dropping. There's no configuration file; all options are command-line arguments. Directory listing is enabled by default and can be disabled with --no-listing. Custom index files can be specified with --index to override the default index.html. The server sends proper caching headers and handles range requests for resumable downloads. For production use, darkhttpd supports daemonization, PID file creation, and logging. The chroot and uid/gid options provide security isolation. While not designed for high-traffic sites, it's excellent for local development, embedded systems, or serving static content where simplicity is valued.

参数

--port _port_
Port to listen on (default: 80 when running as root, otherwise 8080).
--addr _address_
Address to bind to (default: all interfaces).
--daemon
Fork into background.
--pidfile _file_
Write PID to file when daemonized.
--log _file_
Log requests to file (- for stdout).
--index _file_
Default index file to serve for directory requests (default: index.html).
--no-listing
Disable directory listing (directory listing is enabled by default).
--timeout _seconds_
Connection timeout (default: 60).
--uid _uid_
Drop privileges to this user ID.
--gid _gid_
Drop privileges to this group ID.
--chroot
Chroot to docroot.
--maxconn _n_
Limit number of simultaneous connections.
--forward _host_ _url_
301 redirect requests with matching Host header to the given URL.
--forward-all _url_
301 redirect all requests to the given URL (catch-all).
--forward-https _host_ _url_
301 redirect HTTP requests for host to HTTPS.
--no-keepalive
Disable HTTP keep-alive.
--no-server-id
Omit Server identification header from responses.
--mimetypes _file_
Load MIME types from file.
--default-mimetype _type_
Serve files with unknown extensions as this MIME type.
--hide-dotfiles
Do not serve files or directories starting with a dot.
--single-file _file_
Serve only the specified file rather than a directory.
--auth _user:password_
Enable HTTP Basic authentication.
--syslog
Use syslog for request logging instead of a file.
--header _header_
Add a custom response header (repeatable).

FAQ

What is the darkhttpd command used for?

darkhttpd is a simple, fast, and secure static web server. Written in C with no dependencies, it compiles to a single small binary that can serve static files with minimal resource usage. The server is designed for simplicity: it serves files from a document root directory with proper MIME types, handles HTTP/1.1 keep-alive connections, and supports security features like chroot and privilege dropping. There's no configuration file; all options are command-line arguments. Directory listing is enabled by default and can be disabled with --no-listing. Custom index files can be specified with --index to override the default index.html. The server sends proper caching headers and handles range requests for resumable downloads. For production use, darkhttpd supports daemonization, PID file creation, and logging. The chroot and uid/gid options provide security isolation. While not designed for high-traffic sites, it's excellent for local development, embedded systems, or serving static content where simplicity is valued.

How do I run a basic darkhttpd example?

Run `darkhttpd .` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --port _port_ do in darkhttpd?

Port to listen on (default: 80 when running as root, otherwise 8080).