Skip to content

Commit 32c972b

Browse files
committed
feat: Add the TLS and proxy option
1 parent 7575480 commit 32c972b

File tree

12 files changed

+179
-3
lines changed

12 files changed

+179
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ You can execute `docker-compose up -d --build --force-recreate` to start and bui
99

1010
It is possible to adapt the `pretixuser` crontab entries by modifying the [crontab](docker/pretix/crontab.bak) file.
1111

12+
## TLS setup
13+
14+
You can specify the used TLS certificates by adapting the mounted [certificate](docker/pretix/files/config/ssl/domain.crt) and [key](docker/pretix/files/config/ssl/domain.key) e.g. from LetsEncrypt or generating new self-signed certificates by following the [manual](scripts/EXAMPLE-CERT-CREATION.md) and moving the generated files.
15+
1216
## Contribution
1317
If you would like to contribute something, have an improvement request, or want to make a change inside the code, please open a pull request.
1418

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ services:
1212
volumes:
1313
- pretix_data:/data
1414
- ./docker/pretix/pretix.cfg:/etc/pretix/pretix.cfg
15+
- ./docker/pretix/nginx/nginx.conf:/etc/nginx/nginx.conf
1516
- ./docker/pretix/crontab:/tmp/crontab
1617
ports:
17-
- "8000:80"
18+
- "80:80"
19+
- "443:443"
1820
networks:
1921
- backend
2022

docker/pretix/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ FROM pretix/standalone:stable
22

33
USER root
44

5-
ENV IMAGE_CRON_DIR="/image/cron"
5+
ENV IMAGE_CRON_DIR="/image/cron" \
6+
IMAGE_CONFIG_DIR="/image/config"
67

78
ADD files /image
89
COPY crontab /tmp/crontab
910

1011
RUN mv /image/supervisord/crond.conf /etc/supervisord/crond.conf && \
11-
pip install crontab && chmod +x $IMAGE_CRON_DIR/cron.py
12+
pip install crontab && chmod 644 $IMAGE_CONFIG_DIR/ssl/*.crt && chmod +x $IMAGE_CRON_DIR/cron.py
1213

1314
USER pretixuser
1415

16+
EXPOSE 443
17+
1518
ENTRYPOINT ["pretix"]
1619
CMD ["all"]

docker/pretix/files/config/ssl/.placeholder

Whitespace-only changes.

docker/pretix/files/config/ssl/domain.crt

Whitespace-only changes.

docker/pretix/files/config/ssl/domain.key

Whitespace-only changes.

docker/pretix/nginx/nginx.conf

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
user www-data www-data;
2+
worker_processes auto;
3+
pid /var/run/nginx.pid;
4+
daemon off;
5+
worker_rlimit_nofile 262144;
6+
7+
events {
8+
worker_connections 16384;
9+
multi_accept on;
10+
use epoll;
11+
}
12+
13+
http {
14+
server_tokens off;
15+
sendfile on;
16+
charset utf-8;
17+
tcp_nopush on;
18+
tcp_nodelay on;
19+
20+
log_format private '[$time_local] $host "$request" $status $body_bytes_sent';
21+
22+
types_hash_max_size 2048;
23+
server_names_hash_bucket_size 64;
24+
25+
include /etc/nginx/mime.types;
26+
default_type application/octet-stream;
27+
add_header X-Content-Type-Options nosniff;
28+
29+
access_log /var/log/nginx/access.log private;
30+
error_log /var/log/nginx/error.log;
31+
add_header Referrer-Policy same-origin;
32+
33+
gzip on;
34+
gzip_disable "msie6";
35+
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml image/svg+xml;
36+
gzip_vary on;
37+
gzip_proxied any;
38+
gzip_comp_level 6;
39+
gzip_buffers 16 8k;
40+
41+
include /etc/nginx/conf.d/*.conf;
42+
43+
server {
44+
listen 80 backlog=4096 default_server;
45+
listen [::]:80 ipv6only=on default_server;
46+
listen 443 backlog=4096 default_server ssl;
47+
listen [::]:443 ipv6only=on default_server ssl;
48+
server_name _;
49+
ssl_certificate /image/config/ssl/domain.crt;
50+
ssl_certificate_key /image/config/ssl/domain.key;
51+
52+
index index.php index.html;
53+
root /var/www;
54+
55+
location /media/ {
56+
alias /data/media/;
57+
expires 7d;
58+
access_log off;
59+
}
60+
location ^~ /media/cachedfiles {
61+
deny all;
62+
return 404;
63+
}
64+
location ^~ /media/invoices {
65+
deny all;
66+
return 404;
67+
}
68+
location /static/ {
69+
alias /pretix/src/pretix/static.dist/;
70+
access_log off;
71+
expires 365d;
72+
add_header Cache-Control "public";
73+
add_header Access-Control-Allow-Origin "*";
74+
gzip on;
75+
}
76+
location / {
77+
# Very important:
78+
# proxy_pass http://unix:/tmp/pretix.sock:;
79+
# is not the same as
80+
# proxy_pass http://unix:/tmp/pretix.sock:/;
81+
# In the latter case, nginx will apply its URL parsing, in the former it doesn't.
82+
# There are situations in which pretix' API will deal with "file names" containing %2F%2F, which
83+
# nginx will normalize to %2F, which can break ticket validation.
84+
proxy_pass http://unix:/tmp/pretix.sock:;
85+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
86+
proxy_set_header Host $http_host;
87+
}
88+
}
89+
}

scripts/EXAMPLE-CERT-CREATION.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Example of the cert creation for the Nginx setup
2+
3+
## Creation
4+
5+
Please execute the following script `bash create-tls-certs.sh` to create all necessary certificates for the complete setup of all related components.
6+
7+
## Adaptation
8+
9+
Please adjust the configuration files inside the [config](./config) folder and adapt the corresponding values for the req_distinguished_names and subjectAltNames based on your organisation and configuration. You can find [here](https://support.dnsimple.com/articles/what-is-common-name/) and [here](https://learn.microsoft.com/en-us/azure/application-gateway/self-signed-certificates) more information about the corresponding values and CA certificates in general.
10+
11+
## Ca Certificates
12+
13+
### Nginx
14+
15+
Describes the Certificate Authority (certificate & key) for the Nginx server.
16+
17+
## Server Certificates
18+
19+
### Nginx
20+
21+
Describes the server certificate and key for the Nginx server, and it's signed by the Nginx CA.

scripts/certs/.placeholder

Whitespace-only changes.

scripts/config/ca_nginx.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[req]
2+
distinguished_name = req_distinguished_name
3+
default_bits = 4096
4+
prompt = no
5+
default_md = sha256
6+
7+
[req_distinguished_name]
8+
C = DE
9+
ST = Baden-Wuerttemberg
10+
L = Mannheim
11+
O = TheIOTStudio
12+
CN = Pretix Nginx CA
13+
emailAddress = [email protected]
14+
15+
[ext]
16+
subjectKeyIdentifier=hash
17+
authorityKeyIdentifier=keyid:always,issuer
18+
basicConstraints = critical, CA:TRUE, pathlen:3
19+
keyUsage = critical, cRLSign, keyCertSign
20+
nsCertType = sslCA, emailCA

0 commit comments

Comments
 (0)