I have to serve a Django app from a subdirectory (hostname/service/). So far I'm able to get to the Admin Login prompt (hostname/service/admin/login/?next=/admin/), but after successfully logging in I'm redirected to (hostname/admin/login/) and get a 404.
How can I keep the correct subdirectory and get inside the Admin panel?
Here's the nginx.conf server block:
server {
listen 80;
root /usr/share/nginx/html/;
charset utf-8;
location /service {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://djangoapp:8000/;
proxy_set_header X-Real-IP $remote_addr;
}
location /static {
alias /usr/src/app/static;
}
}
Edit: These are the urlpatterns from urls.py:
from django.conf.urls import url, include
from django.contrib import admin
# A custom view of my own
from app.views import AdvanceCustomSearchView
urlpatterns = [
url(r'^search/$', AdvanceCustomSearchView(), name='index_search'),
url(r'^app/', include('app.urls')),
url(r'^admin/', admin.site.urls),
]
You need to add the FORCE_SCRIPT_NAME
setting to your settings.py
as such:
FORCE_SCRIPT_NAME = '/service'
mind that there's no trailing slash at the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With