Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


    Cloudron Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular

    Solved Where can I put custom nginx conf that won't be overwritten?

    Support
    reverseproxy nginx
    5
    21
    675
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • kaxline
      kaxline last edited by girish

      I'm trying to put my Ghost blog at the /blog route of my domain, while my static site is served from the / root via Surfer.

      I've got this config at the bottom of the Cloudron-generated .conf file for the Ghost app:

      location /blog {
           proxy_pass http://172.18.17.251:2368;
      }
      
      location / {
            proxy_pass http://172.18.17.70:3000;
      }
      

      Which gets overwritten quite often, at least once a day. It there a better way to do this routing or a different file to store the config in so that it doesn't get overwritten?

      Or do I need to setup a cron to just place it back in whenever it gets overwritten?

      I've read through a few posts here about nginx proxying but its hard to figure out the best method from what's been posted.

      Thanks!

      girish robi 2 Replies Last reply Reply Quote 0
      • nebulon
        nebulon Staff last edited by

        As you said, this will eventually get overwritten and currently none of the apps are packaged in a way to allow them to run on subpaths of other apps. Usually apps require this knowledge for link sharing or links in transactional emails, so I guess you will hit other issues anyways.

        I think the current only option is, to put a html meta redirect file at /blog which redirects to the ghost domain.

        kaxline robi 2 Replies Last reply Reply Quote 1
        • Topic has been marked as a question  nebulon nebulon 
        • kaxline
          kaxline @nebulon last edited by

          @nebulon OK thanks for this. Won't the redirect have to point to a different domain or subdomain though? I need them to share a root domain in order for the blog traffic to contribute to the static site's SEO.

          https://re-public.io --> Surfer, static
          https://re-public.io/blog --> Ghost

          girish 1 Reply Last reply Reply Quote 0
          • robi
            robi @nebulon last edited by

            @nebulon said in Where can I put custom nginx conf that won't be overwritten?:

            I think the current only option is, to put a html meta redirect file at /blog which redirects to the ghost domain.

            That's app level, what about host level?

            Life of Advanced Technology

            1 Reply Last reply Reply Quote 1
            • girish
              girish Staff @kaxline last edited by

              @kaxline said in Where can I put custom nginx conf that won't be overwritten?:

              Which gets overwritten quite often, at least once a day.

              This shouldn't happen. The nginx config is only overwritten on a Cloudron update (and that too only if the update has any changes to nginx configuration). App updates also don't re-generate the nginx file. Maybe we have a bug somewhere but I have put some logs in my dev setup to see if this is reproducible here and what's causing this.

              Note that every time, you do something that needs the app's container to be re-created, the nginx has to be re-generated. This is done because of the proxy_pass referencing the container by IP address. A container is recreated when you change it's location, email address, change storage, portbindings etc.

              kaxline 1 Reply Last reply Reply Quote 1
              • girish
                girish Staff @kaxline last edited by

                @kaxline said in Where can I put custom nginx conf that won't be overwritten?:

                I need them to share a root domain in order for the blog traffic to contribute to the static site's SEO.

                Not a SEO expert, so.. Is this a valid assumption that putting things in subdomains helps with SEO ?

                (If it's a hypothesis, I guess that's fine too. Maybe we can try to add something on Cloudron side to allow subpaths to redirect to another app but this has security implications we have to think through like cookies/sessions/email notifications etc).

                kaxline 1 Reply Last reply Reply Quote 1
                • kaxline
                  kaxline @girish last edited by

                  @girish OK, interesting. It's happening twice a day at the exact same times. 5am and 5pm PT. Here's a screenshot from Uptime Kuma.

                  Screen Shot 2022-03-29 at 5.04.42 AM.png

                  1 Reply Last reply Reply Quote 0
                  • kaxline
                    kaxline @girish last edited by

                    @girish Seems to be the consensus, though Google SEO is an ever-changing black box:

                    https://chrisberkley.com/blog/subdomains-for-seo/

                    I think it makes sense since many sites have wildly different functionality and content based on subdomains.

                    1 Reply Last reply Reply Quote 0
                    • robi
                      robi @kaxline last edited by

                      @kaxline have you tried separating out your changes out of the /etc/nginx/applications dir config file and into something like the sites-available dir in a separate config file?

                      Cloudron doesn't use that dir so it won't be overwriting it with any app updates.

                      Life of Advanced Technology

                      kaxline 1 Reply Last reply Reply Quote 1
                      • kaxline
                        kaxline @robi last edited by

                        @robi I haven't tried that because I'm not sure where to put it in order to have it overwrite the default Cloudron configs. Any suggestions on that? Thanks!

                        girish robi 2 Replies Last reply Reply Quote 0
                        • girish
                          girish Staff @kaxline last edited by

                          @kaxline I think to properly support this, we can look into this for the next release. For the moment, I am still perplexed why those nginx configs are being overwritten everyday. I am not able to reproduce this here atleast.

                          Can you please try this:

                          • Edit some random nginx config file
                          • Add a dummy comment
                          • Can you report back tomorrow if that comment is still there? Or did it disappear?
                          kaxline 1 Reply Last reply Reply Quote 2
                          • robi
                            robi @kaxline last edited by

                            @kaxline there should be an nginx doc somewhere that describes the order in which it loads configs from different directories.

                            Life of Advanced Technology

                            1 Reply Last reply Reply Quote 1
                            • scooke
                              scooke last edited by

                              Rather than trying to get Docker to do something it isn't usually tasked with doing (or perhaps within the Cloudron system), do these posts offer a possible alternative?:

                              https://cloak.ist/blog/how-to-put-a-ghost-blog-at-a-subdirectory-using-cloudflare-workers/

                              https://www.indiehackers.com/product/img-vision/ghost-blog-is-now-hosted-on-main-domain--M6Gt3CSAp3nIFeZKOC-

                              A life lived in fear is a life half-lived

                              kaxline 1 Reply Last reply Reply Quote 1
                              • kaxline
                                kaxline @girish last edited by

                                @girish OK, I chose a couple of the other app configs and added a comment. They were overwritten along with the Ghost config I originally was asking about. Any thoughts? Anything significant about the 5am/5pm PT time? Want me to test anything else? Send you some logs?

                                girish 1 Reply Last reply Reply Quote 0
                                • kaxline
                                  kaxline @scooke last edited by

                                  @scooke Yes! Thank you! I was looking at how to do this with Cloudflare right off the bat but couldn't find how to do it. Working now!

                                  I would say this is less about Docker and more about Nginx. It would be nice to easily route subdirectory paths to different Cloudron apps via Nginx. Maybe in the UI there's a way to add a directory path in the Location panel.

                                  Thanks again!

                                  girish 1 Reply Last reply Reply Quote 1
                                  • girish
                                    girish Staff @kaxline last edited by

                                    @kaxline To give some update here, I put the comment in some of our internal cloudrons. I can confirm that in some of them the nginx configs are overwritten. I will investigate as to why.

                                    1 Reply Last reply Reply Quote 0
                                    • robi
                                      robi last edited by

                                      One can use the include /path/...; command for additional appX.conf files

                                      I believe, you could use this configuration:

                                      server {
                                          server_name example.com;
                                          listen      [::]:80;
                                          listen      80;
                                      
                                          include /path/to/applications/*/nginx.conf;
                                      }
                                      

                                      and then in each application's directory configure the redirection like this:

                                      location    /app1 {
                                          proxy_pass  http://app1;
                                          proxy_http_version 1.1;
                                          proxy_set_header Upgrade $http_upgrade;
                                          proxy_set_header Connection "upgrade";
                                          proxy_set_header Host $http_host;
                                          proxy_set_header X-Forwarded-Proto $scheme;
                                          proxy_set_header X-Forwarded-For $remote_addr;
                                          proxy_set_header X-Forwarded-Port $server_port;
                                          proxy_set_header X-Request-Start $msec;
                                      }
                                      

                                      Life of Advanced Technology

                                      1 Reply Last reply Reply Quote 1
                                      • girish
                                        girish Staff @kaxline last edited by

                                        @kaxline I found the issue! Can you please try this one-liner - https://git.cloudron.io/cloudron/box/-/commit/6839ff4cf60cb725d224619ee55bcf066a496a12 . The file to edit is /home/yellowtent/box/src/reverseproxy.js . After that, the nginx configs will not get overwritten everyday.

                                        kaxline 1 Reply Last reply Reply Quote 2
                                        • kaxline
                                          kaxline @girish last edited by

                                          @girish I ended up going with a Cloudflare script, which feels a little cleaner for now. I'll try this when I revisit the issue. Thanks for all your help!

                                          robi 1 Reply Last reply Reply Quote 1
                                          • robi
                                            robi @kaxline last edited by

                                            @kaxline can you kindly share your script?

                                            We have other Cloudflare users here who may benefit from your experience. 😄

                                            Life of Advanced Technology

                                            kaxline 1 Reply Last reply Reply Quote 2
                                            • Topic has been marked as solved  girish girish 
                                            • Referenced by  P Prinzhorn 
                                            • kaxline
                                              kaxline @robi last edited by

                                              @robi Yes, sorry, I just followed the tutorial that was previously posted by @scooke

                                              https://cloak.ist/blog/how-to-put-a-ghost-blog-at-a-subdirectory-using-cloudflare-workers/

                                              1 Reply Last reply Reply Quote 1
                                              • Referenced by  kaxline kaxline 
                                              • Referenced by  E eganonoa 
                                              • Referenced by  E eganonoa 
                                              • First post
                                                Last post
                                              Powered by NodeBB