How can I update the nginx config directly in discourse/docker ..?

inside the web template file, I found the instructions where it update the nginx config file template (replace statements) …
Isn’t there away to add a whole new section to nginx config ???

/uploads folder in discourse/shared is accessible from nginx … I want to add a new folder /photos …
is there a direct way (discourse recommended way)

Can you explain why you want to do that?

“Photos” can in any case be uploaded to Discourse. Image upload and optimisation is built into Discourse already.

Maybe I have mentioned ther wrong example … what I’m trying to figure out is … how can I reach the origianl nginx config and add a whoe section inside whether adding a new mapping for a folder or anything else … is that doable ? or it’s just not recommended ?

I can install an external nginx server and make it redirect all links to the docker nginx and do my stuff …

You might find a similar technique to edit the config in this old advice works for you:

(taken from a prior version of this wiki post: Set up Let’s Encrypt with multiple domains)

"It’s pretty simple really, add something like the following to your app.yml hooks section:

Step 2 - discourse.conf

In addition to step 1 there is a change needed for nginx to correctly redirect http to https for anything other than DISCOURSE_HOSTNAME

    - replace:
        filename: "/etc/nginx/conf.d/discourse.conf"
        from: /return 301 https.+/
        to: |
          return 301 https://$host$request_uri;

We also need to remove the additional rewrite that web.ssl.template.yml adds since it forces only the DISCOURSE_HOSTNAME and now we have others!

    - replace:
        filename: "/etc/nginx/conf.d/discourse.conf"
        from: /gzip on;[^\}]+\}/m
        to: |
          gzip on;
          add_header Strict-Transport-Security 'max-age=31536000'; # remember the certificate for a year and automatically connect to HTTPS for this domain

Yes I found these instructions inside the template files …
Isn;t there an instruction to append a new section ? instead of find-replace ??

You are going to have to get creative, I suspect.

Why not tell us why you need this extra folder? It’s possible that someone else has had a similar need, but that the assumed solution isn’t the only way to achieve it.

1 Like

I said it was a bad example … I can manage any extra folder with different solutions … no issues so far …
Yet, I want to be able to add a whole new section in the nginx config … I’m just curios how to do it if I had to do it …

Any chance you could pattern match as I proposed, the match being the pattern at the end of the file, then replace the pattern with the same but with your changes added onto the end?

I thought so …
I was wondering maybe there is a mahic field for newly appended section … defined for this purpose …
never mind … I think I can manage based on your suggestion

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.