Welcome! Log In Create A New Profile

Advanced

Re: django app static files on the different server not get loaded

Francis Daly
January 02, 2022 07:54AM
On Fri, Dec 31, 2021 at 05:45:07PM -0500, ningja wrote:

Hi there,

> I have two server test1.com and test2.com. test1 is internet public face
> server. Test2 is intranet only server. Both servers have nginx docker
> running.

I think you are saying that the world can access https://test1.com/app1/,
and can access the Django that is on test1 -- but the static files are
below the url /static/, not the url /app1/static/.

And the world can access https://test1.com/app2/, and can access the
Django that is on test2, but cannot access the static files there, because
they are also below the url /static/ and not the url /app2/static/.

In that case, the simplest thing from the nginx perspective will probably
be for you to change the config of both Django apps so that the one
on test1.com believes that it is installed below /app1/ with all of
its static files below the url /app1/static/; and so that the one on
test2.com believes that it is installed below /app2/ with all of its
static files below the url /app2/static/.


There are other things you could do instead -- but fundamentally, if
"app2" does not want to be reverse-proxied (at a different part of the
local url hierarchy than it thinks it is installed at), then "app2"
can make itself be difficult to reverse-proxy; and it is often simpler
to configure "app2" to let itself be reverse-proxied, than to fight it.

> How can config nginx1 to looking for app2 static file under test2.com
> https://test2.com/app2/?

nginx gets a request for /static/img/logo-2.jpg

If you know that that request should be reverse-proxied (with proxy_pass)
to the test2.com server, then you must tell nginx to proxy_pass it to
test2.com. And (presumably) you must tell nginx not to proxy_pass the
request for /static/img/logo-1.jpg.

You can do it; but it will probably be easier to do if all of app2 static
image requests are below /app2/static/img/, not /static/img/.

> #test2 server
> server{
> listen 444;
> server_name https://test2.com;

I don't think it's directly relevant here, but that possibly would be better as

listen 444 ssl;
server_name test2.com;

(although I'm not quite clear which parts of your config are in the
test1 server nginx.conf and which are in the test2 server nginx.conf).

Cheers,

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

django app static files on the different server not get loaded

ningja December 31, 2021 05:45PM

Re: django app static files on the different server not get loaded

Francis Daly January 02, 2022 07:54AM

Re: django app static files on the different server not get loaded

ningja January 02, 2022 04:26PM

Re: django app static files on the different server not get loaded

Paul January 02, 2022 06:34PM

Re: django app static files on the different server not get loaded

ningja January 02, 2022 08:56PM

Re: django app static files on the different server not get loaded

ningja January 03, 2022 08:52AM

Re: django app static files on the different server not get loaded

Francis Daly January 03, 2022 05:54AM

Re: django app static files on the different server not get loaded

ningja January 03, 2022 08:49AM

Re: django app static files on the different server not get loaded

ningja January 03, 2022 09:59AM

Re: django app static files on the different server not get loaded

ningja January 03, 2022 05:58PM

Re: django app static files on the different server not get loaded

Francis Daly January 05, 2022 10:52AM

Re: django app static files on the different server not get loaded

ningja January 05, 2022 11:36AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 47
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready