-1

I have django application, hosted using gunicorn,supervisord and nginx.
Following are the config files

nginx.conf

    upstream app_server {
        server unix:/home/jfraixedes/run/gunicorn.sock fail_timeout=0;
    }

    server {
        listen 80;

        # add here the ip address of your server
        # or a domain pointing to that ip (like example.com or www.example.com)
        server_name <ip here> 127.0.0.1 localhost;

        keepalive_timeout 5;
        client_max_body_size 4G;

        access_log /home/jfraixedes/logs/nginx-access.log;
        error_log /home/jfraixedes/logs/nginx-error.log debug;

        location /static/ {
            alias /home/jfraixedes/el-escape/static/;
        }

        # checks for static file, if not found proxy to app
        location / {
            try_files $uri @proxy_to_app;
        }

        location @proxy_to_app {
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_redirect off;
          proxy_pass http://app_server;
        }
    }  

gunicorn.conf

#!/bin/bash

NAME="el-escape"
DIR=/home/jfraixedes/el-escape/src
USER=jfraixedes
GROUP=jfraixedes
WORKERS=3
BIND=unix:/home/jfraixedes/run/gunicorn.sock
DJANGO_SETTINGS_MODULE=elescape.settings.production
DJANGO_WSGI_MODULE=elescape.wsgi
LOG_LEVEL=debug
#PYTHONPATH=/home/jfraixedes/el/bin/python3

cd $DIR
source ../../el/bin/activate

export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DIR:$PYTHONPATH

exec ../../el/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $WORKERS \
  --user=$USER \
  --group=$GROUP \
  --bind=$BIND \
  --log-level=$LOG_LEVEL \
  --log-file=- \
#  --worker-class='gevent' \
  --timeout=300

supervisord.conf

[program:elescape]
;#command=sudo bash -c /home/jfraixedes/bin/gunicorn_start
command=/home/jfraixedes/bin/gunicorn_start
user=jfraixedes
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/jfraixedes/logs/gunicorn-error.log
startretries=10

and finally django settings have

DEBUG = False

ALLOWED_HOSTS = ['domainname.com', 'ipaddress', '127.0.0.1', 'localhost'] 

the problem is, whenever I hit domainname.com or ipaddress, 301 happens and comes up nothing. browser turn http to https.

2
  • How have you verified that it is a 301 Moved permanently response from the server and not for example a HSTS header causing the browser automatically to load the site with HTTPS? There is nothing in these files that would correspond to this behaviour, the redirect happens in your application if it happens at all. Sep 30, 2017 at 9:02
  • @TeroKilkanen you are absolutely correct, I had set SECURE_SSL_REDIRECT = True in my Django settings. Sep 30, 2017 at 11:44

1 Answer 1

1

This is my mistake, I had set SECURE_SSL_REDIRECT = True in my django settings. I had completely forgotten it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .