Reputation: 101
Hi I've been trying to correctly configure apache as reverse proxy for my django application. When served from port :4300 it goes all fine, but when I tried to use reverse-proxy all goes wrong.
When I try to acces when logged in
192.168.100.201/fact
I get the expected functionality, but when I press anything to admin app of django i get
192.168.100.201/admin
when I should get
192.168.100.201/fact/admin
Even if I write it in the browser I'm still redirected to 192.168.100.201/admin
I kwon that maybe is a dub question but it is something that I couldnt realize.
settings.py
"""
Django settings for SEMFAC project.
Generated by 'django-admin startproject' using Django 1.11.13.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
import os
from django.utils.translation import ugettext_lazy as _
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'wkf8aie3kc6@xb0-_y%rwmp*tq)hqv7t+d0l6a9wop0l$1m336'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['192.168.100.205','192.168.100.203','192.168.100.201']
# Application definition
INSTALLED_APPS = [
'fact.apps.FactConfig',
'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 = 'SEMFAC.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 = 'SEMFAC.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/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/1.11/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/1.11/topics/i18n/
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
LANGUAGES = (
('en-US', _('English')),
('es-MX', _('Espanol')),
)
LANGUAGE_CODE = 'es-MX'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
LOGIN_REDIRECT_URL = '/'
LOGIN_URL = '/'
LOGOUT_REDIRECT_URL = '/'
TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')
In the urls.py file this is the configuration
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^',include('fact.urls')),
url(r'^admin/', admin.site.urls),
]
In my django.conf file the configuration is the following
<VirtualHost 192.168.100.205:4300>
Alias /static /opt/SEMFAC/fact/static
<Directory /opt/SEMFAC/fact/static>
Require all granted
</Directory>
<Directory /opt/SEMFAC/SEMFAC>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess SEMFAC python-path=/opt/SEMFAC:/opt/SEMFAC/lib/python2.7/site-packages
WSGIProcessGroup SEMFAC
WSGIScriptAlias / /opt/SEMFAC/SEMFAC/wsgi.py
</VirtualHost>
And the configuration within apache i have
<Location /fact>
ProxyPreserveHost On
ProxyPass http://192.168.100.205:4300
ProxyPassReverse http://192.168.100.205:4300
</Location>
Upvotes: 2
Views: 6193
Reputation: 101
So this is what did the trick
<VirtualHost 192.168.100.205:4300>
Alias /fact/static /opt/SEMFAC/fact/static
<Directory /opt/SEMFAC/fact/static>
Require all granted
</Directory>
<Directory /opt/SEMFAC/SEMFAC>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess SEMFAC python-path=/opt/SEMFAC:/opt/SEMFAC/lib/python2.7/site-packages
WSGIProcessGroup SEMFAC
WSGIScriptAlias /fact /opt/SEMFAC/SEMFAC/wsgi.py
</VirtualHost>
<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass /fact http://192.168.100.205:4300/fact
ProxyPassReverse /fact http://192.168.100.205:4300/fact
ServerName localhost
</VirtualHost>
Upvotes: 3