Configuring domain name using Django and Nginx

Hello there,

I’m sorry if this question seems simple or if it already has been asked.

I have installed and configured with success my Django app, working with nginx server and uwsgi.

I own the domain name and when I try to access it, I have this Django page :

Obviously, when I try to access my website with /realty everything works fine.
I just would like to access the realty app directly from

Here is my nginx config file :

# the upstream component nginx needs to connect to
upstream django {
   server unix:///var/LTU/LTU.sock; # for a file socket

# configuration of the server
server {
   # the port your site will be served on
   listen 80;
   listen 443 ssl;
   # the domain name it will server for
   charset utf-8;

   ssl_certificate /etc/ssl/;
   ssl_certificate_key /etc/ssl/;

   # max upload size
   client_max_body_size 75M;

   # Django media
   location /media {
      alias /var/LTU/media;

   # Django static
   location /static {
      alias /var/LTU/static;

   # Finally, send all non-media requests to the Django server.
   location / {
      uwsgi_pass django;
      include /var/LTU/uwsgi_params;

It seems easy but I’m a little lost between my domain name provider, nginx and Django configuration, anyone could help ?

Thank you :slight_smile:

What does your root file look like?

Hello KenWhitesell and thanks for your reply :slight_smile:

Here is my root :

from django.contrib import admin
from django.urls import path
from django.conf.urls.static import static
from django.conf import settings
from django.conf.urls import url, include

urlpatterns = [
    path('realty/', include('realty.urls')),
    url(r"^realty/", include(("realty.urls", "realty"), namespace='realty')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

So the issue here is that you don’t have a url to match an empty request.

You’ve got a couple different ways to handle this, your choices mostly depending upon how you’re looking to expand things in the future.
(Also, it appears to me that you’ve got duplicate mappings between the first and third entries, both matching to ‘realty/’. I’d lose that third entry - url(…). )

The easiest way I can think of to add this is to add an entry along the lines of:

path(’’, RedirectView.as_view(url=’/realty/’…)),


Thanks, it seems to work perfectly :slight_smile:

I will take a loot about first and third entries too, thanks for the advice.