You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/configuration/command-line-arguments.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,6 @@ The server can be configured via the following command-line arguments.
9
9
10
10
```
11
11
$ static-web-server -h
12
-
13
12
A cross-platform, high-performance and asynchronous web server for static files-serving.
14
13
15
14
Usage: static-web-server [OPTIONS] [COMMAND]
@@ -85,8 +84,10 @@ Options:
85
84
Server TOML configuration file path [env: SERVER_CONFIG_FILE=] [default: ./config.toml]
86
85
--log-remote-address [<LOG_REMOTE_ADDRESS>]
87
86
Log incoming requests information along with its remote address if available using the `info` log level [env: SERVER_LOG_REMOTE_ADDRESS=] [default: false] [possible values: true, false]
87
+
--log-x-real-ip [<LOG_X_REAL_IP>]
88
+
Log the X-Real-IP header for remote IP information [env: SERVER_LOG_X_REAL_IP=] [default: false] [possible values: true, false]
88
89
--log-forwarded-for [<LOG_FORWARDED_FOR>]
89
-
Log real IP from X-Forwarded-For header [env: SERVER_LOG_FORWARDED_FOR] [default: false] [possible values: true, false]
90
+
Log the X-Forwarded-For header for remote IP information [env: SERVER_LOG_FORWARDED_FOR=] [default: false] [possible values: true, false]
90
91
--trusted-proxies <TRUSTED_PROXIES>
91
92
A comma separated list of IP addresses to accept the X-Forwarded-For header from. Empty means trust all IPs [env: SERVER_TRUSTED_PROXIES] [default: ""]
Copy file name to clipboardExpand all lines: docs/content/features/logging.md
+24-3Lines changed: 24 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,8 @@ static-web-server \
13
13
--log-level "trace"
14
14
```
15
15
16
+
> Note: The log format is not well defined and is subject to change.
17
+
16
18
## Log Remote Addresses
17
19
18
20
SWS provides *Remote Address (IP)* logging for every request via an `INFO` log level.
@@ -42,17 +44,36 @@ INFO static_web_server::info: log requests with remote IP addresses: enabled=tru
42
44
INFO static_web_server::handler: incoming request: method=GET uri=/ remote_addr=192.168.1.126:57625
43
45
INFO static_web_server::handler: incoming request: method=GET uri=/favicon.ico remote_addr=192.168.1.126:57625
44
46
```
45
-
## Log Real Remote IP
46
47
47
-
When used behind a reverse proxy the reported `remote_addr` indicates the proxies IP address and port, not the clients real IP.
48
+
## Logging Client IP from X-Real-IP header
49
+
50
+
Some upstream proxies will report the client's real IP address in the `X-Real-IP` header.
51
+
52
+
To enable logging of the X-Real-IP header, enable the `--log-x-real-ip` option or the equivalent [SERVER_LOG_X_REAL_IP](../configuration/environment-variables.md#server_log_x_real_ip) environment variable.
53
+
54
+
When enabled, the log entries will look like:
55
+
56
+
```log
57
+
INFO static_web_server::handler: incoming request: method=GET uri=/ x_real_ip=203.0.113.195
58
+
```
59
+
60
+
If the value of the `X-Real-IP` header does not parse as an IP address, no value will be logged.
61
+
62
+
To restrict the logging to only requests that originate from trusted proxy IPs, you can use the `--trusted-proxies` option, or the equivalent [SERVER_TRUSTED_PROXIES](../configuration/environment-variables.md#server_trusted_proxies) env. This should be a list of IPs, separated by commas. An empty list (the default) indicates that all IPs should be trusted.
63
+
64
+
## Logging Client IP from X-Forwarded-For header
65
+
66
+
> Note: This header should only be trusted when you know your upstream is handling X-Forwarded-For securely and when using the `--trusted-proxies` option.
67
+
68
+
When used behind a reverse proxy the reported `remote_addr` indicates the proxies IP address and port, not the client's real IP.
48
69
The Proxy server can be configured to provide the [X-Forwarded-For header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For), containing a comma-separated list of IP addresses, starting with the *real remote client IP*, and all following intermediate proxies (if any).
49
70
50
71
51
72
To enable logging of the real remote IP, enable the `--log-forwarded-for` option or the equivalent [SERVER_LOG_FORWARDED_FOR](../configuration/environment-variables.md#server_log_forwarded_for) env. By default this will log all requests which have a correctly formatted `X-Forwarded-For` header.
52
73
53
74
Since the content of the `X-Forwarded-For` header can be changed by all proxies in the chain, the remote IP address reported may not be trusted.
54
75
55
-
To restrict the logging to only trusted proxy IPs, you can use the `--trusted-proxies` option, or the equivalent [SERVER_TRUSTED_PROXIES](../configuration/environment-variables.md#server_trusted_proxies) env. This should be a list of IPs, separated by commas. An empty list (the default) indicates that all IPs should be trusted.
76
+
To restrict the logging to only requests that originate from trusted proxy IPs, you can use the `--trusted-proxies` option, or the equivalent [SERVER_TRUSTED_PROXIES](../configuration/environment-variables.md#server_trusted_proxies) env. This should be a list of IPs, separated by commas. An empty list (the default) indicates that all IPs should be trusted.
0 commit comments