why does my django site url reveal the directory path on the server?

Hello.

I am deploying a django site for the first time to a cpanel server with phusion passenger on cloudlinux and i have discovered a weird phenomenon that can’t be normal.

When I go to the site homepage the URL displays as defined in the URLconf but when I click on any link the target page loads fine but the url displays the full directory path to the app location on the server.

So, for example, rather than
https://website.net/django_app
I get -
https://website.net/home/userdir/django_site/django_app

I don’t even know where to begin to troubleshoot this as all the deployment settings were straightforward but I have clearly done something wrong somewhere.

Here is my passenger_wsgi.py file which I got from a bit of research as the cpanel automatically generated passenger_wsgi does not work ;

  1 import os
  2 import sys
  3 
  4 import django.core.handlers.wsgi
  5 from django.core.wsgi import get_wsgi_application
  6 
  7 # Set up paths and environment variables
  8 sys.path.append(os.getcwd())
  9 os.environ['DJANGO_SETTINGS_MODULE'] = 'django_site.deployment_settings'
 10 
 11 # Set script name for the PATH_INFO fix below
 12 SCRIPT_NAME = os.getcwd()
 13 
 14 class PassengerPathInfoFix(object):
 15     """
 16         Sets PATH_INFO from REQUEST_URI because Passenger doesn't provide it.
 17     """
 18     def __init__(self, app):
 19         self.app = app
 20 
 21     def __call__(self, environ, start_response):
 22         from urllib.parse import unquote
 23         environ['SCRIPT_NAME'] = SCRIPT_NAME
 24         request_uri = unquote(environ['REQUEST_URI'])
 25         script_name = unquote(environ.get('SCRIPT_NAME', ''))
 26         offset = request_uri.startswith(script_name) and len(environ['SCRIPT_NAME']) or 0
 27         environ['PATH_INFO'] = request_uri[offset:].split('?', 1)[0]
 28         return self.app(environ, start_response)
 29 
 30 # Set the application
 31 application = get_wsgi_application()
 32 application = PassengerPathInfoFix(application)

I hope somebody can help,
Thanks.

Does the question not make sense ?
If it’s too dumb, sincerely apologies. Just point me to the relevant bit in the documentation and I’d be very grateful as I can’t find it for want of looking !
Thanks :blush:

There’s a question I can answer.

The question makes sense. However, to the extent of my knowledge, it’s more going to be an issue of how the web server is configured rather than your application.

Does the longer url work? If you were to directly enter https://website.net/home/userdir/django_site/django_app as the url, does it take you to the expected page? If so, that would be a sign to me that the web server is routing based on the longer name and not the shorter. I could be wrong - this is just a gut-hunch.

I’d be trying to track it down through the vendor or a support site of theirs.

Hi Ken and thanks.
Yes, I thought it might be a server issue hence the wsgi code as I thought the experience might be familiar to somebody. But then I suppose this may well not the best forum for Phusion Passenger queries after all.

Please endulge me a dumb question on semantics though if you wouldn’t mind ?.. confirm for me who is the vendor in this context please ? my WebHost or my platform ? page loads equally effectively typing the long or short url but the url displayed in the address bar is the long form which is not optimum.

Thanks again for replying

Sure - in this context, the “vendor” would be the organization responsible for configuration of the web server. (“Web server” in this context being a reference to Apache httpd, nginx, lightspeed, etc.) That’s the component responsible for mapping URLs to applications.

You never know who knows what around here - it was certainly worth a shot.

Hi @accafella
Did you find the solution to above issue?