1

Was wondering if there was a way to prepend all URLs with a particular URL. I'll explain the challenge, perhaps I'm going about it all wrong:

Imagine I have three sites all built using Django that are run using nginx and within separate docker containers: main_site, project1 and project2.

When navigating to https://main_site, this should load the pages in main_site as normal. But when navigating to https://main_site/projects/project_1/, This should navigate to project 1.

And similarly, when navigating to https://main_site/projects/project_2/, this should load the pages from project 2.

I've managed to make this somewhat work using nginx and docker.

I have rules something along the lines of:

location / {
    proxy_pass http://main_site;
}

location /projects/project_1 {
    proxy_pass http://project_1;
}

location /projects/project_2 {
    proxy_pass http://project_2;
}

This works perfectly for the homepage (minus the static assets). But, whenever we use template tags in Django, the links in creates is always relative to root (/something/), whenever on any link, it takes me back to the main_site.

I get why this is happening, because everything is happening on the same port.

Question is, is there a way to prepend a URL to all the URLs (static assets as well) without fundamentally having to add reverse or something. I don't want to have to manually add the link to all pages.

Or, does anyone know of a better way to overcome this challenge?

Salaah Amin
  • 382
  • 3
  • 14
  • Does this answer your question? https://stackoverflow.com/a/56639722/7838574 – Daniel Butler Jun 05 '21 at 22:14
  • I dont know about nginx but in apache we have proxypassreverse for this problem – Mohamed ElKalioby Jun 06 '21 at 05:35
  • Why don't you simply [`include` (Django docs)](https://docs.djangoproject.com/en/3.2/topics/http/urls/#including-other-urlconfs) your other projects urls into your main site (you will need to add all of the projects apps to `INSTALLED_APPS`)? – Abdul Aziz Barkat Jun 06 '21 at 08:03
  • I don't think that would be the way to go. In the example there's only 2 projects but really there's quite a bit and each project is it's own site that comes along with its own docker -compose where often there'd be conflicting service names and other silly issues. – Salaah Amin Jun 06 '21 at 12:10
  • Essentially, what this is is for my portfolio. Right now I have each project on a different website and because I've cheaped for a lot of them I don't even have a domain name, so people visiting would need to punch in the ipv4 address. The is so I can pretty much have everything all under the same domain. – Salaah Amin Jun 06 '21 at 12:11

0 Answers0