nginx / uwsgi不提供任何请求

时间:2014-05-26 11:38:37

标签: django nginx https uwsgi

我有nginx,uwsgi,django堆栈。使用来自nginx的https服务,但我试图禁用它。

这是我的nginx配置文件:

nginx.conf:

events {
worker_connections 768;
# multi_accept on;
}

http {

proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

位点可用/ mysite.com:

upstream django {
server 127.0.0.1:44000;
}

server {
listen          80 default;
server_name     www.mysite.com mysite.com;


charset         utf-8;
access_log      /var/log/nginx/mysite_access.log;
error_log       /var/log/nginx/mysite_error.log;

location /static/ {
    root   /opt/myapp/myapp/;
    index  index.html index.htm;
}

location / {
  uwsgi_pass  django;
  include     uwsgi_params;
}
}

当我使用uwsgi运行时,我收到此错误:

django.core.exceptions.SuspiciousOperation: Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): www.mysite.com
[pid: 12865|app: 0|req: 1/2] 84.94.36.146 () {36 vars in 571 bytes} [Mon May 26 07:12:55 2014] GET /favicon.ico => generated 0 bytes in 457 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)

我把'www.mysite.com'放在settings.py的ALLOWED_HOSTS部分,但没有帮助。 这些是我在settings.py中添加的行:

ALLOWED_HOSTS = [
'.mysite.com', # Allow domain and subdomains
'.mysite.com.', # Also allow FQDN and subdomains
]

当我使用runserver运行它时出现此错误:

[26/May/2014 06:53:09] code 400, message Bad request syntax ('\x00;\x02\x00\x0c\x00QUERY_STRING\x00\x00\x0e\x00REQUEST_METHOD\x03\x00GET\x0c\x00CONTENT_TYPE\x00\x00\x0e\x00CONTENT_LENGTH\x00\x00\x0b\x00REQUEST_URI\x0c\x00/favicon.ico\t\x00PATH_INFO\x0c\x00/favicon.ico\r\x00DOCUMENT_ROOT\x0f\x00/etc/nginx/html\x0f\x00SERVER_PROTOCOL\x08\x00HTTP/1.1\x0b\x00REMOTE_ADDR\x0c\x0084.94.36.146\x0b\x00REMOTE_PORT\x05\x0051792\x0b\x00SERVER_PORT\x02\x0080\x0b\x00SERVER_NAME\x10\x00www.mysite.com\t\x00HTTP_HOST\x10\x00www.mysite.com\x0f\x00HTTP_CONNECTION')
[26/May/2014 06:53:09] ";
                         QUERY_STRINGREQUEST_METHODGET
                                                      CONTENT_TYPECONTENT_LENGTH
                                                                                REQUEST_URI
                                                                                           /favicon.ico PATH_INFO
DOCUMENT_ROOT/etc/nginx/htmlSERVER_PROTOCOHTTP/1.1                                                               /favicon.ico
                                                  REMOTE_ADDR
                                                             84.94.36.146
                                                                         REMOTE_PORT51792
                                                                                         SERVER_PORT80
                                                                                                      SERVER_NAMEwww.mysite.com HTTP_HOSTwww.mysite.comHTTP_CONNECTION" 400 -

我读到这个错误可能是由HTTPS请求引起的,但我觉得我在任何地方都没有将HTTP请求重定向到HTTPS,因为我删除了所有这些配置。

任何想法?

由于

2 个答案:

答案 0 :(得分:0)

现在正在运作。 问题是ALLOWED_HOSTS已经在local_settings.py中定义了旧域。我更新了域名并且有效。 所有nginx配置都是正确的,因此这里附带的文件很有用。 谢谢你的时间。

答案 1 :(得分:0)

我使用

解决了这个问题

uwsgi --socket :8001 --wsgi-file test.py

而不是

python manage.py runserser