mongoose/docs/Usage.md

87 lines
3.6 KiB
Markdown
Raw Normal View History

2014-01-05 04:12:07 +08:00
# Mongoose User Guide
2013-10-18 23:57:59 +08:00
2014-01-05 04:12:07 +08:00
Mongoose is small and easy to use web server built on top of
mongoose library. It is designed with maximum simplicity in mind. For example,
2014-03-10 03:26:58 +08:00
to share any directory, just drop mongoose executable in that directory,
2014-01-05 04:12:07 +08:00
double-click it (on UNIX, run it from shell) and launch a browser at
[http://localhost:8080](http://localhost:8080) Note that 'localhost' should
be changed to a machine's name if a folder is accessed from other computer.
2013-10-18 23:57:59 +08:00
2014-01-05 04:12:07 +08:00
On Windows and Mac, Mongoose iconifies itself to the system tray when started.
2014-03-10 03:26:58 +08:00
Right-click on the icon to pop up a menu, where it is possible to stop
2014-01-05 04:12:07 +08:00
mongoose, or configure it.
2013-10-18 23:57:59 +08:00
2014-01-05 04:12:07 +08:00
On UNIX, `mongoose` is a command line utility. Running `mongoose` in
2013-10-18 23:57:59 +08:00
terminal, optionally followed by configuration parameters
(`mongoose [OPTIONS]`) or configuration file name
(`mongoose [config_file_name]`) starts the
2014-01-05 04:12:07 +08:00
web server:
$ mongoose -document_root /var/www # Running mongoose with cmdline options
$ mongoose /etc/my_config.txt # Running mongoose with config file
$ mongoose # Running with no parameters. This will
# serve current directory on port 8080
Mongoose does not detach from terminal. Pressing `Ctrl-C` keys
stops the server.
2013-10-18 23:57:59 +08:00
When started, mongoose first searches for the configuration file.
2014-01-05 04:12:07 +08:00
If configuration file is specified explicitly in the command line, then
specified configuration file is used.
2013-10-18 23:57:59 +08:00
Otherwise, mongoose would search for file `mongoose.conf` in the same directory
where binary is located, and use it. Configuration file can be absent.
Configuration file is a sequence of lines, each line containing
2014-01-05 04:12:07 +08:00
command line argument name and it's value. Empty lines and lines beginning
with `#` are ignored. Here is the example of `mongoose.conf` file:
2013-10-18 23:57:59 +08:00
2014-01-05 04:12:07 +08:00
# This is a comment
document_root C:\www
listening_port 80
ssl_certificate C:\mongoose\ssl_cert.pem
2013-10-18 23:57:59 +08:00
2014-01-05 04:12:07 +08:00
Command line arguments are highest priority and can override
configuration file settings. For example, if `mongoose.conf` has line
2013-10-18 23:57:59 +08:00
`document_root /var/www`, and mongoose has been started as
2014-01-05 04:12:07 +08:00
`mongoose -document_root /etc`, then `/etc` directory will be used as
document root.
2013-10-18 23:57:59 +08:00
Note that configuration options on the command line must start with `-`,
2014-01-05 04:12:07 +08:00
and their names are the same as in the config file. Exampli gratia,
the following two setups are equivalent:
2013-10-18 23:57:59 +08:00
2014-01-05 04:12:07 +08:00
$ mongoose -listening_port 1234 -document_root /var/www
2013-10-18 23:57:59 +08:00
2014-01-05 04:12:07 +08:00
$ cat > mongoose.conf
2013-10-18 23:57:59 +08:00
listening_ports 1234
document_root /var/www
2014-01-05 04:12:07 +08:00
^D
2013-10-18 23:57:59 +08:00
$ mongoose
Mongoose can also be used to modify `.htpasswd` passwords file:
2014-01-05 04:12:07 +08:00
$ mongoose -A .htpasswd mydomain.com user_name user_password
2013-10-18 23:57:59 +08:00
Unlike other web servers, mongoose does not require CGI scripts be located in
a special directory. CGI scripts can be anywhere. CGI (and SSI) files are
recognized by the file name pattern. Mongoose uses shell-like glob
patterns. Pattern match starts at the beginning of the string, so essentially
patterns are prefix patterns. Syntax is as follows:
2014-03-10 03:26:58 +08:00
** Matches everything
* Matches everything but slash character, '/'
? Matches any character
$ Matches the end of the string
| Matches if pattern on the left side or the right side matches.
2013-10-18 23:57:59 +08:00
All other characters in the pattern match themselves. Examples:
2014-03-10 03:26:58 +08:00
# Pattern Meaning
**.cgi$ Any string that ends with .cgi
/foo Any string that begins with /foo
**a$|**b$ Any string that ends with a or b
2013-10-18 23:57:59 +08:00
2014-01-05 04:12:07 +08:00
To restrict CGI files only to `/cgi-bin/` directory, use this setting:
2013-10-18 23:57:59 +08:00
2014-01-05 04:12:07 +08:00
$ mongoose -cgi_pattern /cgi-bin/*.cgi # Emulate /cgi-bin/ restriction