Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将nginx配置为django主机?_Django_Nginx - Fatal编程技术网

如何将nginx配置为django主机?

如何将nginx配置为django主机?,django,nginx,Django,Nginx,我使用django主机和nginx。 例如,hosts.py host_patterns = patterns('project', host(r'', 'urls', name=''), host(r'beta', 'private_urls', name='beta'), ) nginx.conf server { listen 80; server_name example.ru *.example.ru 174.61.223.135; access_log /var/log/

我使用django主机和nginx。 例如,hosts.py

host_patterns = patterns('project',
  host(r'', 'urls', name=''),
  host(r'beta', 'private_urls', name='beta'),
)
nginx.conf

server {
listen 80;
server_name example.ru *.example.ru 174.61.223.135;
access_log  /var/log/nginx/example.log;

location /static/ {
    alias /home/path/to/static/;
}

location / {
    proxy_pass http://127.0.0.1:8000;
    proxy_set_header Host $server_name;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}
但是当我打开beta.example.ru时,django不会从hosts.py获取设置。它接受url默认主机(r'','url',name=''),而不从主机查找url(r'beta','private_url',name='beta')
如何配置nginx.conf?

$server\u name
变量不是您所认为的。使用
$host
$http\u host
。谢谢!!这是工作:)