RFC: Automatically handle nginx domain and make letsencrypt setup simpler#3543
Conversation
eb2ef69 to
c763871
Compare
|
I'll split the server name to separate file, just to make simpler to document if it needs to be changed. |
|
I think I can split this up to smaller change-sets, so it is not so much changing in one PR? |
b7a0bbb to
5f0b239
Compare
|
With this PR I think there is no differences on production docker-compose and main-branch docker-compose. Hopefully making the update/testing simpler also from that point of view. |
hughrun
left a comment
There was a problem hiding this comment.
I think this is a positive move forward - we have a lot of Issues and comments about making nginx setup simpler and for me the ideal scenario is someone can create an .env and just spin up an instance without touching docker or nginx files.
This seems to work fine in development, but with a few caveats that at the very least will require a breaking changes note and further updated documentation.
localhost works fine out of the box (as long as PORT has not been set), but anyone using ngrok will need to adjust their settings.
Up to this change, I have been using ngrok for development, running through port 1333:
ngrok http 1333But this PR changes this behaviour in potentially confusing ways. It reverses the existing behaviour of developing on localhost vs ngrok because we move from publishing on port 1333 to 80.
Up until this change, devs would set PORT to 1333 if using localhost, and not set a value for PORT if using ngrok or something similar.
Now if PORT is not set, then instead of running through 1333 we are using 80, even when USE_HTTPS is True. But if we set PORT to 1333, BookWyrm will load initially, but we end up with a CSRF error on any form submission. That is, we have to not set PORT, and run ngrok with ngrok http 80.
|
Thanks for checking this, you found really good points
I think this has come from mismatch between .env.example comments on PORT and actual nginx-config in main branch. .env file mentions that PORT should be set if it is wanted to be something else than default, I followed that approach by the idea that .env file modifications should be enough for most of the cases. But you are right, it breaks the config that is currently in place and needs some more documentation or highlighting.
One option that I was thingking was to introduce the But I'll check if I can introduce the On domain part, I agree. I'll remove the www-subdomain. |
If we can avoid further complicating But if setting |
I think it is problem only with I was thingking that more feasible flow for that could be to set Now that I look at those, I'm not sure if I can add the commits on the changes that I'm mentioning here, so it might be easier to follow what I mean? |
Yes I think you're right. And now that you ask, I haven't done anything special with nginx so I'm not really sure - ngrok serves both http and https but if I tried
Yes please! |
…y in docker-compose run Include env defined nginx to nginx default.conf automatically Add nginx-variable to .env.example
…d config periodically certbot will do renew once a day and nginx script will tell nginx to reload config once a day, so within 2 days when certificate is valid to be renewed, it is in use.
Development config was pretty much same as reverse-proxy and can be easily confusing which should be used. Now we make distinction just if you have something in front of nginx or does nginx handle the ssl traffic. If you use ssl certificates in docker-compose nginx, use https mode, if you have something in front of nginx, use revese-proxy mode
we can have revese-proxy with use-https enabled, but we just don't want letsencrypt in that case trying to update certificates
32d81a5 to
ee08f8c
Compare
|
I ended up with flow that USE_HTTPS indicates if connections should come via https, either something in front of nginx terminating them or nginx directly. NGINX_SETUP=https to tell that nginx should handle certificates and ssl. settings changes were added so that if we have reverse_proxy, we still most likely have something in default port to listen connections and that default should be used. I'm not sure how good assumption that is, but it should address the case that you have ngrok listening https/http and bookwyrm is in reverse_proxy mode. I also changed the certbot entrypoint to check NGINX_SETUP mode, that indicates more if we assume nginx/letsencrypt to handle certificates than USE_HTTPS. |
hughrun
left a comment
There was a problem hiding this comment.
Ok this looks good! Just a question about the ports interpolation in docker-compose.
Description
This PR is build on top of #3540 on splitting up nginx config. It contains new bw-dev command and separated docker-compose -file just to bootstrap letsencrypt certificate. It allows documentation to be simplied so docker-compose or nginx-config files don't need to be modified manually when setting up bookwyrm with https.
One key point in certbot is that I added
--keep-until-expiringcompared to production command, this makes it run in mode that it gets certificate if not present, otherwise it checks if current one needs to be renewed or not. So should be pretty safe to run always. It can also replace renew command to my understanding.Docker-compose file is also modified so it takes the PORT configuration into account from .env and .env file now contains
NGINX_SETUPvariable to tell if nginx should be in development, production (https) or reverse-proxy mode. Use only needs to modify .env file to change between those, no need to modify nginx-files or copy those over or modify docker-compose.Certbot container is added and it has entrypoint to run renew and sleep a day if USE_HTTPS is configured to be true in .env. This allows to run the stack without cron-script setup.
Nginx deployment has small entrypoint script added that will periodically tell nginx to reload config, this takes renewed certificates into use automatically.
docker-compose.yml#1786What type of Pull Request is this?
Does this PR change settings or dependencies, or break something?
Details of breaking or configuration changes (if any of above checked)
Documentation
Tests