0

I'm using django 1.9,gunicorn,nginx and postgres as database for my website. My site is up and running but when i try to login as admin or user i get server error 500 on webpage and on terminal i get "is the server running on host 139.59.45.246 and accepting tcp/ip connections on port 5432".


I thought there might be a problem in postgres.conf and pg_hba.conf. But there are 2 host all all....one for IPv4 and one for IPv6 in pg_hba.conf.


I can't figure out how to edit pg_hba.conf. Please use above's IP to explain.


One more thing will it solve the problem or i might need to do something else?


Here my settings.py-

import os

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

SECRET_KEY = '^4z+c_2^di81mt7sj@e8c&_b%###############'

DEBUG = False

ALLOWED_HOSTS = ['irenovate.in', '139.59.45.246']

INSTALLED_APPS = [
    # django apps
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # my apps
    'website',
    'accounts',

    # third party apps
    'crispy_forms',
]

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

ROOT_URLCONF = 'irenovate.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 = 'irenovate.wsgi.application'


# Database

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': '########',
        'USER': '########',
        'PASSWORD': '........',
        'HOST': '139.59.45.246',
        'PORT': '',
    }
}

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_in_env", "static")

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static_in_project", "our_static"),
)

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_in_env", "media_root")

CRISPY_TEMPLATE_PACK = 'bootstrap3'
sudorm
  • 1
  • 3
  • 1
    Sometimes you just need to restart the postgres server: `sudo /etc/init.d/postgresql restart` – Alan Avalos Feb 02 '17 at 18:12
  • how does the variable `DATABASES` in `settings.py` look like? Also as the comment above says - is the db running? Try running `psql ` in a shell if that works. – yedpodtrzitko Feb 02 '17 at 18:12
  • @yedpodtrzitko when i did psql , i got this- perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LC_CTYPE = "en_IN", LANG = "en_US.UTF-8" are supported and installed on your system. perl: warning: Falling back to a fallback locale ("en_US.UTF-8"). psql: FATAL: role "root" does not exist – sudorm Feb 02 '17 at 20:39
  • check if postgres is listening in that ip: `pg_isready -h 139.59.45.246` if not set the ip in postgresql.conf `listen_addresses = 'localhost, 139.59.45.246'` and restart the server `sudo /etc/init.d/postgresql restart` – alfredo138923 Feb 02 '17 at 22:56
  • @alfredo138923 i tried **pg_isready -h 139.59.45.246** and it gave me a error **perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LC_CTYPE = "en_IN", LANG = "en_US.UTF-8" are supported and installed on your system. perl: warning: Falling back to a fallback locale ("en_US.UTF-8"). 139.59.45.246:5432 - no response** and so i modified the **postgres.conf** file. i'm still getting the server error 500 – sudorm Feb 03 '17 at 05:48
  • @sudorm I think you're getting these errors due to another reason. If running the postgres commands sends you perl warnings about the locales, you could try this instead: http://stackoverflow.com/questions/17712700/postgres-locale-error – Alan Avalos Feb 03 '17 at 06:58
  • thanks a lot guys. I solved it yesterday – sudorm Feb 04 '17 at 07:04
  • @sudorm what was it? I'm getting a similar error and I have no idea what it is – M. Ryan Jun 06 '17 at 21:26

0 Answers0