使用unix套接字时Django ALLOWED_HOSTS应该是什么?

协同org

我正在使用unix套接字而不是TCP端口供gunicorn从中服务我的Django应用程序。但是,当调试关闭时,除非设置,否则将收到400响应ALLOWED_HOSTS = ['*']在这种情况下,比“ *”更安全的选择是什么?

这是我的Gunicorn启动脚本(/opt/example.com/bin/gunicorn_start):

#!/bin/bash

NAME="myapp"                                      # Name of the application
DJANGODIR=/opt/example.com/myapp                  # Django project directory
SOCKFILE=/opt/example.com/run/gunicorn.sock       # we will communicate using this unix socket
USER= myuser                                      # the user to run as
GROUP=mygroup                                     # the group to run as
NUM_WORKERS=3                                     # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=myapp.settings             # which settings file should Django use
DJANGO_WSGI_MODULE=myapp.wsgi                     # WSGI module name

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source ../bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --log-level=debug \
  --bind=unix:$SOCKFILE
协同org

原来,我只需要添加服务器的主机名。我一直在使用['localhost','127.0.0.1'],但是由于我也添加了以下nginx配置,因此该应用需要允许网站的URL。

upstream blog_app_server {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).

  server unix:/opt/example.com/run/gunicorn.sock fail_timeout=0;
}

server {
    listen       80;
    server_name  www.example.com example.com;
    server_tokens off;
    access_log /opt/example.com/logs/nginx-access.log;
    error_log /opt/example.com/logs/nginx-error.log;

    location /static/ {
        alias /opt/example.com/static/;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        if (!-f $request_filename) {
            proxy_pass http://blog_app_server;
            break;
        }
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

具体来说,我认为这是proxy_set_header Host $http_host;我需要将站点名称添加到ALLOWED_HOSTS的那一行

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我的json应该是什么样的?使用Web套接字发送消息

[:: 1]在Django中的ALLOWED_HOSTS是什么意思?

使用jpmml openscoring REST api时,pmml文件的输入应该是什么

使用“in-package”时参数类型应该是什么?

使用连续移动ONVIF时可选的`Timeout`值应该是什么值

不使用Dynamo DB本地时,端点URL应该是什么?

使用函数 randomForest 时,分类变量的类型应该是什么?

当没有数据要返回时,GraphQL突变返回类型应该是什么?

重新启动单元文件时,模式和通道应该是什么

交叉编译时,CMake的link.txt中的链接器命令应该是什么?

在查找数组中的最大数时,数组的正确声明应该是什么?

使用keras和tensorflow的卷积神经网络(CNN)的输入应该是什么?

使用git的IntelliJ上的Scala:.gitignore应该是什么样子?

使用CQL jdbc驱动程序时连接字符串应该是什么

使用SWIG的C函数的JNI包装器-类型映射应该是什么?

使用cordova应用程序,openFB中的oauthRedirectURL应该是什么样的?

使用Enzyme和useContext钩子的简单集成测试应该是什么样的?

使用 Keras 进行迁移学习。最后一层激活应该是什么?

在导轨上使用bootstrap-sass红宝石时,application.scss应该是什么样子

在 IIS 中托管时,我的 MVC Core 应用程序的 Program 类应该是什么样的?

提交给Google网站站长时,站点地图文件的名称应该是什么?

将ASP .NET投诉字典发送到服务器时,contentType应该是什么

在CSV文件中下载MySQL数据时,CSV文件的Content-Type应该是什么?

将向量传递给函数时,默认参数(如果有)应该是什么?

ALLOWED_HOSTS和Django

Django Allowed_Hosts错误。

在Python中使用Selenium来查找YouTube视频中评论数的CSS选择器应该是什么?

使用 rdbms 数据库中的连接加载数据到 spark 的方法应该是什么

如果我有一个使用yield的cdef或cpdef函数,应该是什么类型?