nginx的/ uwsgi不用于任何要求(nginx/uwsgi don't serve a

2019-10-20 04:17发布

我有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,因为我删除了所有这些配置。

有任何想法吗?

谢谢

Answer 1:

它的工作现在。 问题是,ALLOWED_HOSTS是与旧域local_settings.py已定义。 我更新的领域和它的工作。 所有nginx的配置是正确的,所以在这里的附加文件是有用的。 谢谢你的时间。



Answer 2:

我解决它通过使用

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

代替

python manage.py runserser



文章来源: nginx/uwsgi don't serve any request