django+gunicorn+supervisord+nginx 重定向发生

django+gunicorn+supervisord+nginx 重定向发生

我有 django 应用程序,使用 gunicorn、supervisord 和 nginx 托管。
以下是配置文件

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配置文件

#!/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

监控配置文件

[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

最后,django 设置有

DEBUG = False

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

问题是,每当我点击domainname.com或 时ipaddress,都会发生 301 并且什么都没有出现。浏览器http转向https

答案1

这是我的错误,我已经SECURE_SSL_REDIRECT = True在 django 设置中设置过了。但我完全忘记了。

相关内容