Django/React application error when port forwarding on remote CentOS7 Apache server: 'No routes matched location "/appname"'

25 views Asked by At

I am new to Django/React development and have been practicing development/deployment on a remote CentOS7 Apache server. Due to the remote nature of the server, we are using port forwarding to allow external access. I am using Django (3.2.23), React (18.2.0), CentOS7 Linux, Apache (2.4.6), Mod_WSGI (4.7.1), Webpack (5.89.0) and Python 3.6 with a virtual environment.

The development server runs fine on internal port 8000, forwarded to external port 40731 (as root, ie: www.hostsite.com:40731). The issue arises when I attempt to access the final deployment through internal port 80, accessing it remotely via external port 40730 (ie: www.hostsite.com:40730/cambraatz). To be clear, this is an issue specific to 'final' deployment and NOT an issue with the local Django development server.

When I attempt to visit the website, www.hostsite.com:40730/cambraatz, my index.html file is successfully running (webpage title loads accordingly) however I am served a blank white page. Developer tools is raising a 'No routes matched location "/cambraatz"' error (see snip below). Additionally, the serving of a blank page does not seem to raise any issues with Apache/Linux...code 200 in access_log and no new entries in error_log.

Developer Tools Error Message, request for hostsite.com:40730/cambraatz

Given the aforementioned, I believe the issue is likely due to the Mod_WSGI setup. I dont believe my Django routing is the issue as the development server routing is working as intended and no flagrant errors are being logged on the server, but I may be wrong. From what I can tell, my Apache/Mod_WSGI is successfully finding and running my 'index.html' file but is unable to find the website root.

Additional requests to /admin and /api pages return standard Django 404 pages (as DEBUG=True for now).

Django DEBUG Page, request for hostsite.com:40730/cambraatz/api

See below for a few of the current state of the pertinent files for reference, I can also share a link to my GitHub however my question keeps getting flagged as spam.

I attempted to clean these up for readability, but apologize in advance for any leftover comments/redundant code leftover from troubleshooting.

File Directory:

cambraatz
 |
 +-- cb-venv (typical venv sub-directory)
 |
 +-- Pipfile
 |
 +-- Pipfile.lock
 |
 +-- website
   |
   +-- api
   |   |
   |   +-- (simple Django api sub-directory for storing contact information in models)
   |
   +-- frontend
   |   |
   |   +-- (Django hosted frontend React application sub-directory)
   |
   +-- website
   |   |
   |   +-- (main Django application, main urls.py, wsgi.py, asgi.py, settings.py, etc.)
   |
   +-- db.sqlite3
   |
   +-- manage.py

/etc/httpd/conf.d/django.conf

<VirtualHost *:80>
   <Directory /home/django-server-cb/cambraatz/website/website>
      <Files wsgi.py>
         Require all granted
      </Files>
   </Directory>
   WSGIDaemonProcess cambraatz
   WSGIProcessGroup cambraatz
   WSGIScriptAlias /cambraatz /home/django-server-cb/cambraatz/website/website/wsgi.py process-group=cambraatz

   Alias /static /home/django-server-cb/cambraatz/website/frontend/static
   <Directory /home/django-server-cb/cambraatz/website/frontend/static>
      Require all granted
   </Directory>
</VirtualHost>

/home/django-server-cb/cambraatz/website/manage.py

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

/home/django-server-cb/cambraatz/website/website/wsgi.py

python_home = '/home/django-server-cb/cambraatz/cb-venv'
activate_this = python_home + '/bin/activate_this.py'

with open(activate_this) as f:
   code = compile(f.read(), activate_this, 'exec')
   exec(code, dict(__file__=activate_this))

import os

import sys

from django.core.wsgi import get_wsgi_application

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings')

application = get_wsgi_application()

/home/django-server-cb/cambraatz/website/website/urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('api.urls')),
    path('', include('frontend.urls')),
]

/home/django-server-cb/cambraatz/website/website/settings.py

from pathlib import Path
import os

__import__('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')

BASE_DIR = Path(__file__).resolve().parent.parent

SECRET_KEY = os.environ.get('DJANGO_CB_SECRET_KEY', 'django-insecure-n^vlgpk!vxzj16l0%j70f5_gn%1l$&j0cu5t+0m-mt*^(i%16o')

DEBUG = 'False'

SESSION_COOKIE_SECURE = True

CSRF_COOKIE_SECURE = True

SECURE_SSL_REDIRECT = False

ALLOWED_HOSTS = ['*']

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'api.apps.ApiConfig',
    'rest_framework',
    'phone_field',
    'frontend.apps.FrontendConfig',
]

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 = 'website.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = 'website.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

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',
    },
]

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

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

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

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

I am happy to share any other files or elaborate on the files above as needed. I cant help but feel I am annoyingly close to getting this up and running and would greatly appreciate any help that can be afforded.

Side Note: I have confirmed that a white page is also being served when the site/server is being accessed locally (ie: without port forwarding).

0

There are 0 answers