Skip to content

Commit 4d07a49

Browse files
Caddyfile documentation (inventree#8798) (inventree#8800)
* basic mixin file * Add basic check for model type support * Enhanced documentation for Caddyfile * Additional documentation around proxy server * Remove code from other PR (cherry picked from commit ecc1c93) Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
1 parent ef5fd93 commit 4d07a49

3 files changed

Lines changed: 59 additions & 9 deletions

File tree

contrib/container/Caddyfile

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
# - INVENTREE_SERVER: The internal URL of the InvenTree container (default: http://inventree-server:8000)
55
#
66
# Note that while this file is a good starting point, it may need to be modified to suit your specific requirements
7+
#
8+
# Ref to the Caddyfile documentation: https://caddyserver.com/docs/caddyfile
79

810

11+
# Logging configuration for Caddy
912
(log_common) {
1013
log {
1114
output file /var/log/caddy/{args[0]}.access.log
1215
}
1316
}
1417

18+
# CORS headers control (used for static and media files)
1519
(cors-headers) {
1620
header Allow GET,HEAD,OPTIONS
1721
header Access-Control-Allow-Origin *
@@ -25,8 +29,10 @@
2529
}
2630
}
2731

28-
# Change the host to your domain (this will serve at inventree.localhost)
29-
{$INVENTREE_SITE_URL:inventree.localhost} {
32+
# The default server address is configured in the .env file
33+
# If not specified, the default address is used - http://inventree.localhost
34+
# If you need to listen on multiple addresses, or use a different port, you can modify this section directly
35+
{$INVENTREE_SITE_URL:http://inventree.localhost} {
3036
import log_common inventree
3137

3238
encode gzip
@@ -35,25 +41,39 @@
3541
max_size 100MB
3642
}
3743

44+
# Handle static request files
3845
handle_path /static/* {
3946
import cors-headers static
4047

4148
root * /var/www/static
4249
file_server
4350
}
4451

52+
# Handle media request files
4553
handle_path /media/* {
4654
import cors-headers media
4755

4856
root * /var/www/media
4957
file_server
5058

59+
# Force download of media files (for security)
60+
# Comment out this line if you do not want to force download
5161
header Content-Disposition attachment
5262

63+
# Authentication is handled by the forward_auth directive
64+
# This is required to ensure that media files are only accessible to authenticated users
5365
forward_auth {$INVENTREE_SERVER:"http://inventree-server:8000"} {
5466
uri /auth/
5567
}
5668
}
5769

58-
reverse_proxy {$INVENTREE_SERVER:"http://inventree-server:8000"}
70+
# All other requests are proxied to the InvenTree server
71+
reverse_proxy {$INVENTREE_SERVER:"http://inventree-server:8000"} {
72+
73+
# If you are running behind another proxy, you may need to specify 'trusted_proxies'
74+
trusted_proxies {
75+
# enter your trusted proxy IP addresses here
76+
}
77+
78+
}
5979
}

docs/docs/start/config.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Note that in [debug mode](./intro.md#debug-mode), some of the above settings are
156156
| `INVENTREE_COOKIE_SAMESITE` | `False` | Disable all same-site cookie checks in debug mode |
157157
| `INVENTREE_SESSION_COOKIE_SECURE` | `False` | Disable secure session cookies in debug mode (allow non-https cookies) |
158158

159-
### INVENTREE_COOKIE_SAMESITE vs INVENTREE_SESSION_COOKIE_SECURE
159+
### Cookie Settings
160160

161161
Note that if you set the `INVENTREE_COOKIE_SAMESITE` to `None`, then `INVENTREE_SESSION_COOKIE_SECURE` is automatically set to `True` to ensure that the session cookie is secure! This means that the session cookie will only be sent over secure (https) connections.
162162

@@ -187,6 +187,11 @@ InvenTree provides support for the [X-Forwarded-Proto](https://developer.mozilla
187187

188188
You can also refer to the [Django documentation]({% include "django.html" %}/ref/settings/#use-x-forwarded-host) for more information on this header.
189189

190+
Proxy configuration can be complex, and any configuration beyond the basic setup is outside the scope of this documentation. You should refer to the documentation for the specific proxy server you are using.
191+
192+
Refer to the [proxy server documentation](./processes.md#proxy-server) for more information.
193+
194+
190195
## Admin Site
191196

192197
Django provides a powerful [administrator interface]({% include "django.html" %}/ref/contrib/admin/) which can be used to manage the InvenTree database. This interface is enabled by default, and available at the `/admin/` URL.

docs/docs/start/processes.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ Further, it provides an authentication endpoint for accessing files in the `/sta
4444

4545
Finally, it provides a [Let's Encrypt](https://letsencrypt.org/) endpoint for automatic SSL certificate generation and renewal.
4646

47+
### Proxy Functionality
48+
49+
#### API and Web Requests
50+
51+
All API and web requests are reverse-proxied to the InvenTree django server. This allows the InvenTree web server to be accessed via a standard HTTP/HTTPS port, and allows the proxy server to handle SSL termination.
52+
4753
#### Static Files
4854

4955
Static files can be served without any need for authentication. In fact, they must be accessible *without* authentication, otherwise the unauthenticated views (such as the login screen) will not function correctly.
@@ -52,15 +58,34 @@ Static files can be served without any need for authentication. In fact, they mu
5258

5359
It is highly recommended that the *media* files are served behind an authentication layer. This is because the media files are user-uploaded, and may contain sensitive information. Most modern web servers provide a way to serve files behind an authentication layer.
5460

55-
#### Example Configuration
61+
### Proxy Configuration
62+
63+
We provide some *sample* configuration files for getting your proxy server off the ground. The exact setup and configuration of your proxy server will depend on your specific requirements, and the software you choose to use. You may be integrating InvenTree with an existing web server, and the configuration may be different to the provided examples.
64+
65+
#### Example Configurations
66+
67+
**Caddy**
68+
69+
The [docker production example](./docker.md) provides an example using [Caddy](https://caddyserver.com) to serve *static* and *media* files, and redirecting other requests to the InvenTree web server itself. Caddy is a modern web server which is easy to configure and provides a number of useful features, including automatic SSL certificate generation.
70+
71+
You can find the sample Caddy configuration [here]({{ sourcefile("contrib/container/Caddyfile") }}).
72+
73+
**Nginx**
74+
75+
An alternative is to run nginx as the reverse proxy. A sample configuration file is provided [here]({{ sourcefile("contrib/container/nginx.conf") }}).
5676

57-
The [docker production example](./docker.md) provides an example using [Caddy](https://caddyserver.com) to serve *static* and *media* files, and redirecting other requests to the InvenTree web server itself.
77+
#### Extending the Proxy Configuration
5878

59-
Caddy is a modern web server which is easy to configure and provides a number of useful features, including automatic SSL certificate generation.
79+
You may wish to extend the proxy configuration to include additional features, based on your particular requirements. Some examples of where additional configuration may be required include:
6080

61-
#### Alternatives to Caddy
81+
- **Upstream Proxy**: You may be running the InvenTree server behind another proxy server, and need to configure the proxy server to forward requests to the upstream proxy.
82+
- **Authentication**: You may wish to add an authentication layer to the proxy server, to restrict access to the InvenTree web interface.
83+
- **SSL Termination**: You may wish to terminate SSL connections at the proxy server, and forward unencrypted traffic to the InvenTree web server.
84+
- **Load Balancing**: You may wish to run multiple instances of the InvenTree web server, and use the proxy server to load balance between them.
85+
- **Custom Error Pages**: You may wish to provide custom error pages for certain HTTP status codes.
6286

63-
An alternative is to run nginx as the reverse proxy. A sample configuration file is provided in the `./contrib/container/` source directory.
87+
!!! warning "No Support"
88+
We do not provide support for configuring your proxy server. The configuration of the proxy server is outside the scope of this documentation. If you require assistance with configuring your proxy server, please refer to the documentation for the specific software you are using.
6489

6590
#### Integrating with Existing Proxy
6691

0 commit comments

Comments
 (0)