diff --git a/Makefile b/Makefile index 7b9aa5dff..f9e7b3fc0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SUBDIRS = src scripts +SUBDIRS = src scripts man all debug clean install: diff --git a/man/Makefile b/man/Makefile new file mode 100644 index 000000000..4b997832f --- /dev/null +++ b/man/Makefile @@ -0,0 +1,10 @@ + +include ../include.mk + +install: + install -d $(INSTALLPREFIX)/man/man1 + install -d $(INSTALLPREFIX)/man/man5 + cp yaws.1 $(INSTALLPREFIX)/man/man1 + cp yaws.conf.5 $(INSTALLPREFIX)/man/man5 + +all debug clean: diff --git a/man/yaws.1 b/man/yaws.1 new file mode 100644 index 000000000..2357cc9db --- /dev/null +++ b/man/yaws.1 @@ -0,0 +1,57 @@ +.TH YAWS "1" "" "" "User Commands" +.SH NAME +yaws \- yet another webserver +.SH SYNOPSIS +.B yaws +[\fIOPTIONS\fR] +.SH DESCRIPTION +.\" Add any additional description here +.PP +Yaws is fast lightweight webserver. It can run as daemon or +in interactive mode where it is possible to directly interact +with the webserver. Yaws is particularly good at generating +dynamic content. See the user docs for more information on that topic. + +.TP +\fB\-i\fR +Interactive mode. This will start yaws in interactive mode with an erlang +prompt. All error_logger messages will be written to the tty as well in this +mode. Use this when developing yaws code. +.TP +\fB\-D\fR +Daemon mode. This will start yaws as a daemon. +.TP +\fB\-d\fR +Debug mode. This will produce some auxilliary error output for some +error conditions. +.TP +\fB\-c file\fR +Use a different configuration file than the default. The default configuration file +when running as root is /etc/yaws.conf. When running as a non priviliged user, yaws +will search for its configuration file in the following order. First in +$HOME/yaws.conf, then in ./yaws.conf and finally in /etc/yaws.conf +.TP +\fB\-t\fR +Traffic trace mode. All traffic will be written to a trace file called trace.traffic +in the log directory. +.TP +\fB\-T\fR +HTTP trace mode. All HTTP messages will be written to a trace file called trace.http +in the log directory. +.TP +\fB\-h\fR +HUP the daemon. This forces the daemon to reread the configuration file. It also makes +the daemon epty all its internal content caches. Hence when updating the doc root, +HUPing the daemon is the fastest way to see the content updates. +.TP +\fB\-s\fR +Stop the daemon. +.TP +\fB\-v\fR +output version information and exit +.SH AUTHOR +Written by Claes Wikstrom +.SH "SEE ALSO" +.BR yaws.conf (5) +.BR erl (1) + diff --git a/man/yaws.conf.5 b/man/yaws.conf.5 new file mode 100644 index 000000000..9ca15f53b --- /dev/null +++ b/man/yaws.conf.5 @@ -0,0 +1,182 @@ +.TH YAWS.CONF "5" "" "" "User Commands" +.SH NAME +/etc/yaws.conf \- Configuration file for the yaws webserver +.SH DESCRIPTION +.\" Add any additional description here +.PP +Yaws is fast lightweight webserver. It reads a configuration file called +yaws.conf to control its operations. The configuration contains two distinct +parts a global part which affects all the virtual hosts and a server part +where options for each virtual host is supplied. + +.SH GLOBAL PART +.TP +\fB\logdir = Directory\fR +All yaws logs will be written to files in this directory. There are several +different log files written by yaws. + +.br +\fBreport.log\fR - this is a text file that contains all error logger +printouts from yaws. +.br +\fBHost.access\fR - for each virtual host served by yaws, a file Host.access +will be written which contains an access log in Common Log Format. +.br +\fBtrace.http\fR - this file contains the HTTP trace if that is enabled +.br +\fBtrace.traffic\fR - this file contains the traffic trace if that is enabled + +.TP +\fB ebin_dir = Directory\fR +This directive adds Directory to the erlang search path. It is possible to +have several of these command in the configuration file. +.TP +\fB include_dir = Directory\fR +This directive adds Directory to the path of directories where the erlang +compiler seraches for include files. We need to use this if we want to +include .hrl files in our yaws erlang code. +.TP +\fB max_num_cached_files = Integer\fR +Yaws will cache small files such as commonly accessed GIF images in RAM. +This directive sets a maximum number on the number of cached files. +The default value is 400. +.TP +\fB max_num_cached_bytes = Integer\fR +This directive controls the total amount of RAM which can maximally be +used for cached RAM files. The default value is 1000000, 1 megabyte. +.TP +\fB max_size_cached_file = Integer\fR +This directive sets a maximum size on the files that are RAM cached by yaws. +The default value i 8000, 8 kBytes. +.TP +\fB trace = traffic | http\fR +This enables traffic or http tracing. Tracing is also possible to enable with +a command line flag to yaws. +.SH SERVER PART +Yaws can virthost several webservers on the same ip address as well +as several webservers on different ip addresses. The on limitation here is +that there can be only one server with ssl enabled per each individual ip address. +.pp +Each virttual host is defined within a matching pair of \fB\fR +and \fB\fR. The ServerName will be the name of the webserver. + +.pp +The following directives are allowed inside a server definition. +.TP +\fBport = Port \fR +This makes the server listen on Port +.TP +\fB listen = IpAddress\fR +This makes the server listen on IpAddress +.TP +\fB docroot = Directory\fR +This makes the server serve all its content from Directory +.TP +\fB default_server_on_this_ip = true | false\fR +When virthosting several servers on the same ip address, this option +is mandatory. When client requests arrive at the ip address whithout the +HTTP Host: header present, we must know which server is the default. +.TP +\fB ssl = true \fR +This enables ssl for this server +.TP +\fB ssl_keyfile = File\fR +Specifies which file contains the private key for the certificate. +.TP +\fB ssl_certfile = File\fR +Specifies which file contains the certificate for the server. +.TP +\fB ssl_cacertfile = File\fR +File If the server is setup to require client certificates. This file needs to contain all the certificates of the acceptable signers for the client certs. +.TP +\fB ssl_verify = 1 | 2 | 3\fR +Specifies the level of verification the server does on clinet certs. 1 means nothing, 2 means the the server will ask the client for a cert but not fail if the client doesn't supply a client cert, 3 means that the server requires the client to supply a client cert. +.TP +\fB ssl_depth = Int\fR +Specifies the depth of certificate chains the server is prepared to follow when verifying client certs. +.TP +\fB ssl_password = String\fR +String If the private key is encrypted on disc, this password is the 3des key to decrypt it. + +.TP +\fB ssl_ciphers = String\fR +* This string specifies the ssl cipher string. The syntax of the ssl cipher string is a little horrible sublanguage of its own. It is documented in the ssl man page for "ciphers". +.SH EXAMPLES + +The following example defines a single server on port 80. +.nf + +logdir = /var/log/yaws + + port = 80 + listen = 192.168.128.31 + docroot = /var/yaws/www + +.fi + +.pp +And this example shows a similar setup but two webservers on the same ip address + +.nf + +logdir = /var/log/yaws + + port = 80 + default_server_on_this_ip = true + listen = 192.168.128.31 + docroot = /var/yaws/www + + + + port = 80 + listen = 192.168.128.31 + docroot = /var/yaws/www_funky_org + + + +.fi + +And finally a sligthly more complex example +with two servers on the same ip, and one ssl server on a +different ip. + +.nf + +logdir = /var/log/yaws +max_num_cached_files = 8000 +max_num_cached_bytes = 6000000 + + + port = 80 + default_server_on_this_ip = true + listen = 192.168.128.31 + docroot = /var/yaws/www + + + + + + port = 80 + listen = 192.168.128.31 + docroot = /var/yaws/www_funky_org + + + + port = 443 + listen = 192.168.128.32 + docroot = /var/yaws/www_funky_org + ssl = true + ssl_keyfile = /etc/funky.key + ssl_cerfile = /etc/funky.cert + ssl_password = gazonk + + + +.fi + +.SH AUTHOR +Written by Claes Wikstrom +.SH "SEE ALSO" +.BR yaws (1) +.BR erl (1) + diff --git a/scripts/yaws.conf.template b/scripts/yaws.conf.template index a6d11b84a..0626149e0 100644 --- a/scripts/yaws.conf.template +++ b/scripts/yaws.conf.template @@ -7,7 +7,6 @@ logdir = /var/log/yaws ebin_dir = %yawsdir%/examples/ebin include_dir = %yawsdir%/examples/include -keepalive_timeout = 15000 diff --git a/scripts/yaws.conf.template.local b/scripts/yaws.conf.template.local index a8133bf6d..63ef67316 100644 --- a/scripts/yaws.conf.template.local +++ b/scripts/yaws.conf.template.local @@ -7,7 +7,6 @@ logdir = . ebin_dir = %yawsdir%/examples/ebin include_dir = %yawsdir%/examples/include -keepalive_timeout = 15000 diff --git a/scripts/yaws.ss b/scripts/yaws.ss index 4af0b513a..04343f0c5 100755 --- a/scripts/yaws.ss +++ b/scripts/yaws.ss @@ -14,6 +14,7 @@ help() echo " yaws -c file -- set config file" echo " yaws -t -- trace all traffic" echo " yaws -T -- trace http traffic" + echo " yaws -v -- print version" echo "" echo "" echo "ctl functions ... " @@ -55,6 +56,9 @@ do -s) exec $erl -noshell -pa ${yawsdir}/ebin -s yaws_ctl stop; exit normal;; + -v) + exec $erl -noshell -pa ${yawsdir}/ebin -s yaws printversion; + exit normal;; *) help esac diff --git a/src/yaws.erl b/src/yaws.erl index 8e7465343..dd8a2ae82 100644 --- a/src/yaws.erl +++ b/src/yaws.erl @@ -607,3 +607,9 @@ oct_to_dig(O) -> oct_to_dig(O, 0). oct_to_dig([], D) -> D; oct_to_dig([H|T], D) -> oct_to_dig(T, D*8 + H - $0). + + + +printversion() -> + io:format("Yaws ~s~n", [yaws_vsn:version()]), + init:stop(). diff --git a/src/yaws_config.erl b/src/yaws_config.erl index 8e4b56e16..0947b0612 100644 --- a/src/yaws_config.erl +++ b/src/yaws_config.erl @@ -18,7 +18,7 @@ paths() -> case os:cmd("id -u") of [$0 |_] -> %% root - ["./yaws.conf", + [ "/etc/yaws.conf"]; _ -> %% developer [filename:join([os:getenv("HOME"), "yaws.conf"]), @@ -187,11 +187,11 @@ fload(FD, globals, GC, C, Cs, Lno, Chars) -> ["trace", '=', Bstr] -> case Bstr of - "true" -> - fload(FD, globals, GC#gconf{trace = true}, + "traffic" -> + fload(FD, globals, GC#gconf{trace = {true, traffic}}, C, Cs, Lno+1, Next); - "false" -> - fload(FD, globals, GC#gconf{trace = undefined}, + "http" -> + fload(FD, globals, GC#gconf{trace = {true, http}}, C, Cs, Lno+1, Next); _ -> {error, ?F("Expect bool at line ~w",[Lno])} @@ -224,6 +224,9 @@ fload(FD, globals, GC, C, Cs, Lno, Chars) -> false -> {error, ?F("Expect directory at line ~w", [Lno])} end; + + + %% keep this bugger for backward compat for a while ["keepalive_timeout", '=', Val] -> case (catch list_to_integer(Val)) of I when integer(I) -> diff --git a/vsn.mk b/vsn.mk index 01e0d6eaf..8bd21c1e3 100644 --- a/vsn.mk +++ b/vsn.mk @@ -1 +1 @@ -YAWS_VSN=0.50 +YAWS_VSN=0.48 diff --git a/www/configuration.yaws b/www/configuration.yaws index e064eb191..545ee495c 100644 --- a/www/configuration.yaws +++ b/www/configuration.yaws @@ -57,46 +57,13 @@ include.mk file in the the toplevel directory.

Running yaws

The yaws executable is a shell script which invokes the erlang system and instructs it to start yaws. -

The following command line flags are availiable: -

+The command line flags for yaws are documented in the man page for +yaws(1). + +out(_) -> + L = os:cmd("man yaws | col -b"), + yaws_api:pre_ssi_string(L). +

Configuring Yaws

@@ -108,221 +75,12 @@ embedded application inside another Erlang program.

Daemon mode

- Yaws look for its configuration file in the following locations: - - - -

The configuration file has a global part and then specific -parts for each virtual host that is defined. A very simple -example config could look like: - - - - -out(A) -> yaws_api:pre_ssi_string(" - -logdir = /var/log/yaws -ebin_dir = /usr/local/myapp/ebin -include_dir = /usr/local/myapp/include -keepalive_timeout = 15000 - - -# enter hostname and IP here - - port = 80 - listen = 201.6.7.8 - docroot = /var/yaws/www - - -"). - - -We have the following possible configuration directives available in -the yaws.conf file: -

Global part

- - -

Server specific part

-

Yaws supports virtual hosting. To let yaws run more than one virtual -webserver we define more than one server entry in the configuration file. -A server entry looks like: - -out(A) -> yaws_api:pre_ssi_string(" - - port = 80 - listen = 201.6.7.8 - docroot = /var/yaws/www - -"). - -The possible configuration directives availible inside a server -entry are: -

- -

A virtual hosting example could look as: - - -out(A) -> yaws_api:pre_ssi_string(" - - default_server_on_this_ip = true - port = 80 - listen = 201.6.7.8 - docroot = /var/yaws/www.mydomain.org - - - - - - default_server_on_this_ip = false - port = 80 - listen = 201.6.7.8 - docroot = /var/yaws/www.noshit.net - - -"). - - - -

SSL

- -Yaws has full SSL support. When we are running SSL it is not -possible to combine that with virtual hosting on the same IP address. -The reason for that is ofcource that the webserver needs to choose -a certificate before it reads the Host: header. - -

The following config options are possible for an SSL server. -

-

- -

In the yaws distribution, an example (self generated) certificate -and key is included in the $YAWSSRC/ssl directory. - -

Extending one of the example from above for SSL usage, it could look -like: - +The yaws configuration is described in the man page for yaws.conf (5) -out(A) -> yaws_api:pre_ssi_string(" - - port = 443 - listen = 201.6.7.8 - docroot = /var/yaws/www - ssl = true - ssl_keyfile = /etc/yaws.key - ssl_certfile = /etc/yaws.cert - - -"). - +out(_) -> + L = os:cmd("man yaws.conf | col -b"), + yaws_api:pre_ssi_string(L). diff --git a/www/dynamic.yaws b/www/dynamic.yaws index 5bcddccba..3917df610 100644 --- a/www/dynamic.yaws +++ b/www/dynamic.yaws @@ -75,6 +75,24 @@ client connection in an uncontrolled way. +

The embedded erlang code can also return a list of the +above values. For example the following value +

+[{status, 303},
+ {allheaders,
+     [{header, ["Location: ","http://www.funky.org/"]},
+      {header, ["Set-Cookie: ","namn=ruler;"]}
+     ]},
+ {html," Redirected to funky.org "}
+]
+
+
+ +

+Can be returned if we want to issue a redirect and set a cookie +at the same time. + +

The argument

The out/1 function is supplied with a record argument. The diff --git a/www/history.yaws b/www/history.yaws index bbbd678c6..62f418e8d 100644 --- a/www/history.yaws +++ b/www/history.yaws @@ -13,10 +13,11 @@ out(A) -> + Jun 12 Redid the out/1 structure completely removed some/all headers and made -it possible to return headers as well as new status code inside any out/1 function. This makes it much easier to write apps in yaws. +it possible to return headers as well as new status code inside any out/1 function. This makes it much easier to write apps in yaws. Also accumulated output into larger write chunks. Performnce enhancer. Jun 11, fixed Etag: and Last-Modified: headers for static content. diff --git a/www/index.yaws b/www/index.yaws index 46de82b2c..20e2dcbfa 100644 --- a/www/index.yaws +++ b/www/index.yaws @@ -54,6 +54,18 @@ powered by Yaws.