Get rid of Port in Base URL in DefaultRouter/Basic root view

Hi, I have deployt a simple Django rest API using vagrant (Ubuntu, Apache2, uwsgi) and everything is working as expected. Except the shown routes for my API (see the Screenshot).

How can I change the host prefix for the urls to match the following strings
http://localhost/api/hello-viewset/, http://localhost/api/profile/, http://localhost/api/login/” and get rid of the port?

As workaround I have forwarded the port 8000 as well, see the Vagrantfile in the Repo. For my production setup I won’t go this path and let the Apache2 proxy handle the whole traffic. For everyone who want’s help me here is a GitHub Repo with the setup.

Just install Oracle VirtualBox and Vagrant and run the init.bat script. After that go to http://localhost/api/

Side note: When posting links as examples and not as references, mark them as “preformatted text” by using the backtick - ` at the beginning and end of the url.
That way, it shows up as a string and not a link: http://localhost/api/login/

Side note 2: Yes, there are some people here who do try to help out with DRF-related issues, but this is not an official DRF support channel. You may get quicker response by asking your question in one of the resources listed at Home - Django REST framework

If I had to make a guess here, I would suggest trying the USE_X_FORWARDED_HOST setting to have Django “see” the original request and not just what is being forwarded.

Also, I’m guessing that you’re using nginx as a proxy (proxy_pass). This might also be able to be resolved by using uwsgi_pass instead.

Thx, I have edited the backticks. Unfortunately I had no luck by using the USE_X_FORWARDED_PORT flag in combination with “RequestHeader set X-Forwarded-Port 80” inside my Apache2 config.

The issue seems to lie on what is passed from uwsgi to the application
“uwsgi --http localhost:8000 --module profiles_project.wsgi:application”.

I was hoping to find a solution where I can override the “string concatenation” inside the “Api Root” view.

I will open this question inside DRF thanks for the hint.

That isn’t the setting I suggested trying. I suggested using the USE_X_FORWARDED_HOST setting.

Hey Ken, I finally made it. Setting the header “RequestHeader set X-Forwarded-Host localhost” raises a useful error message (see the screenshot).

Which leads me on the right track. Setting the header “RequestHeader set HTTP_HOST localhost” solves the issue.