-
-
Notifications
You must be signed in to change notification settings - Fork 299
RFC: Automatically handle nginx domain and make letsencrypt setup simpler #3543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hughrun
merged 9 commits into
bookwyrm-social:main
from
ilkka-ollakka:tweak/automatically_handle_nginx_domain
May 3, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d7c0d16
Move nginx config to templates that will populate domain automaticall…
ilkka-ollakka 428f801
add bw-dev command to init letsencrypt certificate
ilkka-ollakka 1046c2a
change default docker-compose that is works with certbot if configured
ilkka-ollakka 8f4eee3
nginx: split hostname to single-file that is included
ilkka-ollakka c95cfa1
certbot: add automatical certbot loop in container and nginx to reloa…
ilkka-ollakka 8bca77c
remove www-subdomain from nginx and certbot defaults
ilkka-ollakka ba0f204
Rename nginx configs to https and reverse-proxy
ilkka-ollakka 2060372
update certbot entrypoint to check nginx-config
ilkka-ollakka ee08f8c
settings: check if we are behind reverse_proxy when setting netloc
ilkka-ollakka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| services: | ||
| nginx: | ||
| image: nginx:1.25.2 | ||
| ports: | ||
| - "80:80" | ||
| - "443:443" | ||
| networks: | ||
| - main | ||
| environment: | ||
| - DOMAIN=${DOMAIN} | ||
| volumes: | ||
| - ./nginx/locations:/etc/nginx/conf.d/locations | ||
| - ./nginx/server_config:/etc/nginx/conf.d/server_config | ||
| - ./nginx/server_name:/etc/nginx/conf.d/server_name | ||
| - ./nginx/ssl_bootstrap:/etc/nginx/templates/default.conf.template | ||
| - ./certbot/conf:/etc/nginx/ssl | ||
| - ./certbot/data:/var/www/certbot | ||
| certbot: | ||
| image: certbot/certbot:latest | ||
| command: certonly --webroot --webroot-path=/var/www/certbot --keep-until-expiring --email ${EMAIL} --agree-tos --no-eff-email -d ${DOMAIN} | ||
| depends_on: | ||
| - nginx | ||
| volumes: | ||
| - ./certbot/conf:/etc/letsencrypt | ||
| - ./certbot/logs:/var/log/letsencrypt | ||
| - ./certbot/data:/var/www/certbot | ||
| networks: | ||
| main: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/bash | ||
| while true; do | ||
| sleep 1d | ||
| nginx -t && nginx -s reload | ||
| done & |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| include /etc/nginx/conf.d/server_config; | ||
|
|
||
| upstream web { | ||
| server web:8000; | ||
| } | ||
| upstream flower{ | ||
| server flower:8888; | ||
| } | ||
|
|
||
| server { | ||
| listen [::]:80; | ||
| listen 80; | ||
|
|
||
| include /etc/nginx/conf.d/server_name; | ||
|
|
||
| location ~ /.well-known/acme-challenge { | ||
| allow all; | ||
| root /var/www/certbot; | ||
| } | ||
|
|
||
| # redirect http to https | ||
| return 301 https://${DOMAIN}$request_uri; | ||
| } | ||
|
|
||
|
|
||
| server { | ||
| access_log /var/log/nginx/access.log cache_log; | ||
|
|
||
| listen [::]:443 ssl; | ||
| listen 443 ssl; | ||
|
|
||
| http2 on; | ||
|
|
||
| include /etc/nginx/conf.d/server_name; | ||
|
|
||
| client_max_body_size 3M; | ||
|
|
||
| if ($host != "${DOMAIN}") { | ||
| return 301 $scheme://${DOMAIN}$request_uri; | ||
| } | ||
|
|
||
| # SSL code | ||
| ssl_certificate /etc/nginx/ssl/live/${DOMAIN}/fullchain.pem; | ||
| ssl_certificate_key /etc/nginx/ssl/live/${DOMAIN}/privkey.pem; | ||
|
|
||
| location ~ /.well-known/acme-challenge { | ||
| allow all; | ||
| root /var/www/certbot; | ||
| } | ||
|
|
||
| sendfile on; | ||
| tcp_nopush on; | ||
| tcp_nodelay on; | ||
| keepalive_timeout 65; | ||
| types_hash_max_size 2048; | ||
| #include /etc/nginx/mime.types; | ||
| #default_type application/octet-stream; | ||
|
|
||
| gzip on; | ||
| gzip_disable "msie6"; | ||
|
|
||
| proxy_read_timeout 1800s; | ||
| chunked_transfer_encoding on; | ||
|
|
||
| # store responses to anonymous users for up to 1 minute | ||
| proxy_cache bookwyrm_cache; | ||
| proxy_cache_valid any 1m; | ||
| add_header X-Cache-Status $upstream_cache_status; | ||
|
|
||
| # ignore the set cookie header when deciding to | ||
| # store a response in the cache | ||
| proxy_ignore_headers Cache-Control Set-Cookie Expires; | ||
|
|
||
| # PUT requests always bypass the cache | ||
| # logged in sessions also do not populate the cache | ||
| # to avoid serving personal data to anonymous users | ||
| proxy_cache_methods GET HEAD; | ||
| proxy_no_cache $cookie_sessionid; | ||
| proxy_cache_bypass $cookie_sessionid; | ||
|
|
||
| include /etc/nginx/conf.d/locations; | ||
|
|
||
| } | ||
|
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| server_name ${DOMAIN}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| server { | ||
| listen [::]:80; | ||
| listen 80; | ||
|
|
||
| include /etc/nginx/conf.d/server_name; | ||
|
|
||
| location ~ /.well-known/acme-challenge { | ||
| allow all; | ||
| root /var/www/certbot; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.