1đź‘Ť
First you must realize that django won’t serve your static or media files by default, you should use your HTTP server (nginx, apache or other) for that.
Next thing to do is to configure your HTTP server to serve “/path/to/your/project/public” and any files inside on root URL of your domain, and instead of serving 404 error if file is not found, it should redirect to django (so if there is some file in path /site/something/ your HTTP server should serve that file, if not, it shoudl serve anything that django will output on that path. Sample configuration for nginx might look like this:
server {
listen 80;
server_name oskar.local;
root /path/to/your/project/public;
location @default {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
include /etc/nginx/uwsgi_params;
uwsgi_pass app_server; # or some proxy_pass if you're not using uwsgi
break;
}
location / {
try_files $uri @default;
}
}
And last step is to configure your django app’s MEDIA_* settings:
MEDIA_ROOT = "/path/to/your/project/public"
MEDIA_URL = "/"
But be careful! With that approach there is potential vulnerability: any user can put files into path that is normally handled by django. Better approach will be to put all of “sub-sites” inside some sub-directory or into separate domain.