uwsgi + nginx + django keeps showing Django default page.

February 17, 2018 397 views
Django Nginx Ubuntu 16.04
nicooda
By:
nicooda

was following this page to set up uwsgi
https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04

completed tutorial, and after I try to drag and drop my project and modified all url and allow host and sets Default to false. The server keeps showing django default page instead of my own project.

I tried to hit ip.address.name/contact ip.address.name/about
django looks for admin/ only

setting.py

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['67.205.182.29', 'kai-peng.net', 'www.kai-peng.net']


# Application definition

INSTALLED_APPS = [
    'personal',
    'contact',
    'posts',
    'widget_tweaks',
    'django_summernote', 
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'firstsite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates'),],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'firstsite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'EST'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

# sendmail setting
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
DEFAULT_FROM_EMAIL = 'kai.peng@uconn.edu'
EMAIL_HOST_USER = 'kai.peng@uconn.edu'
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False 
EMAIL_PORT = "1025"

EMAIL_HOST = "smtp.mail.com"

url

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



urlpatterns = [
    path('admin/', admin.site.urls), 
    path('', include('personal.urls')),
    path('contact', include('contact.urls')),
    path('posts/', include('posts.urls')),
    path('summernote/', include('django_summernote.urls')),

    ]


if settings.DEBUG:
   urlpatterns = urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

``server {
listen 80;
listen [::]:80;

server_name 67.205.182.29 kai-peng.net www.kai-peng.net;

   location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
    root /home/kai/firstsite/;
}
    location /media/ {
    root /home/kai/firstsite/;
}
location / {
    include         uwsgi_params;
    uwsgi_pass      unix:/run/uwsgi/firstsite.sock;
}

}`

Be the first one to answer this question.