# Module `Ocsigen.Server`

```ocaml
val section : Logs.src
```
```ocaml
val reload : ?file:string -> unit -> unit
```
Reload the configuration of the server. The optional parameter `?file` may be used to read the configuration from another file.

```ocaml
val exec : Xml.xml list list -> unit
```
Start the server with a configuration file. Never returns.

```ocaml
val serve : ?port:int -> ?directory_listing:bool -> dir:string -> unit -> unit
```
`serve ~dir ()` starts a server that serves the static files of directory `dir`, with no configuration file and no log directory required (logs go to `stdout`/`stderr`). This backs the one-command serve mode of the `ocsigenserver` executable (`ocsigenserver ./public`). The Staticmod extension is loaded dynamically on demand, so it does not need to be linked into the program. `port` defaults to 8080\. When `directory_listing` is `true`, directories without an index file are listed. Never returns.

```ocaml
val reverse_proxy : ?port:int -> target:string -> unit -> unit
```
`reverse_proxy ~target ()` starts a server that forwards every request to the `target` base URL (for example `http://localhost:9000`), with no configuration file and no log directory required. This backs `ocsigenserver --reverse-proxy URL`. The Revproxy extension is loaded dynamically on demand. `port` defaults to 8080\. Never returns.

```ocaml
val start : 
  ?ports:(Config.Socket_type.t * int) list ->
  ?ssl_ports:(Config.Socket_type.t * int) list ->
  ?ssl_info:Config.ssl_info option ->
  ?default_charset:string option ->
  ?logdir:string ->
  ?datadir:string ->
  ?uploaddir:string option ->
  ?maxuploadfilesize:int64 option ->
  ?syslog_facility:Syslog_message.facility option ->
  ?configfile:string ->
  ?usedefaulthostname:bool ->
  ?pidfile:string ->
  ?mimefile:string ->
  ?verbose:unit ->
  ?veryverbose:unit ->
  ?silent:unit ->
  ?daemon:unit ->
  ?debug:unit ->
  ?debugmode:bool ->
  ?minthreads:int ->
  ?maxthreads:int ->
  ?max_number_of_connections:int ->
  ?client_timeout:int ->
  ?server_timeout:int ->
  ?shutdown_timeout:float option ->
  ?filebuffersize:int ->
  ?maxrequestbodysize:int64 option ->
  ?maxrequestbodysizeinmemory:int ->
  ?bindir:string ->
  ?extdir:string ->
  ?command_pipe:string ->
  ?disablepartialrequests:bool ->
  ?respect_pipeline:unit ->
  ?maxretries:int ->
  Extensions.host_config list ->
  unit
```
Start the server with some instructions. Never returns. It takes as main parameter a list of virtual hosts (see [`host`](./#val-host) below).

Options behave exactly like their [configuration file](./config.md) counterparts.

```ocaml
type instruction =
  Extensions.virtual_hosts ->
  Extensions.config_info ->
  Ocsigen_base.Lib.Url.path ->
  Extensions.extension
```
The type of instructions to be used inside an host or site. Instructions are defined by extensions (Staticmod, Eliom, etc.)

```ocaml
val register_static_server : (dir:string -> instruction) -> unit
```
Called by the Staticmod extension when it is loaded to publish its static-file serving function, so that [`serve`](./#val-serve) can use it without a static dependency on the extension.

```ocaml
val register_reverse_proxy_server : (target:string -> instruction) -> unit
```
Called by the Revproxy extension when it is loaded to publish its request-forwarding function, so that [`reverse_proxy`](./#val-reverse_proxy) can use it without a static dependency on the extension.

```ocaml
val register_security_headers : instruction -> unit
```
Called by the Securityheaders extension when it is loaded to publish its instruction, so that [`serve`](./#val-serve) can add the safe-by-default security headers without a static dependency on the extension.

```ocaml
val register_compression : instruction -> unit
```
Called by the Deflatemod extension when it is loaded to publish a compression instruction with safe defaults, so that [`serve`](./#val-serve) can compress responses without a static dependency on the extension.

```ocaml
val host : 
  ?regexp:string ->
  ?port:int ->
  ?default_hostname:string ->
  ?default_httpport:int ->
  ?default_httpsport:int ->
  ?default_protocol_is_https:bool ->
  ?mime_assoc:Ocsigen_http.Charset_mime.mime_assoc ->
  ?charset_assoc:Ocsigen_http.Charset_mime.charset_assoc ->
  ?default_directory_index:string list ->
  ?list_directory_content:bool ->
  ?follow_symlinks:[ `Always | `No | `Owner_match ] ->
  ?do_not_serve_404:Extensions.do_not_serve ->
  ?do_not_serve_403:Extensions.do_not_serve ->
  ?uploaddir:string option ->
  ?maxuploadfilesize:int64 option ->
  instruction list ->
  Extensions.host_config
```
You can define one or several virtual hosts corresponding to a given server name or port.

```ocaml
val site : 
  ?charset:string ->
  Ocsigen_base.Lib.Url.path ->
  instruction list ->
  instruction
```
Each host may contain some sub-sites corresponding to subdirectories in the URL.
