django app static files on the different server not get loaded
Francis Daly
francis at daoine.org
Sun Jan 2 12:53:13 UTC 2022
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 at daoine.org
_______________________________________________
nginx mailing list
nginx at nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
More information about the nginx
mailing list