[英]Bad request (400) using nginx on ubuntu with Django
我為我的網絡服務器制作了自己的配置,如果我通過IP訪問我的網站,一切都很完美 - http://179.188.3.54
我沒有更改我的域名,我修改了我的/ etc / hosts本地:
179.188.3.54 cinegloria.com
因此,當我嘗試在瀏覽器上訪問我的網站時,我收到了錯誤的請求(400)。 這是我的nginx配置:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/www;
index index.html index.htm;
access_log /var/log/nginx/domain-access.log;
error_log /var/log/nginx/error.log;
server_name cinegloria.com www.cinegloria.com;
location /static {
alias /cinegloria/cinegloria/cinegloria/static/;
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://0.0.0.0:8000/;
fastcgi_split_path_info ^()(.*)$;
}
}
我不知道什么是錯的,據我所知,我不需要改變其他任何東西。 有任何想法嗎?
什么意思是proxy_pass http:// 0.0.0.0:8000 /? 也許必須有127.0.0.1或179.188.3.54
並在proxy_pass中檢查您的端口
root@RDE-1.3:~# curl -I http://179.188.3.54
HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Tue, 24 Feb 2015 15:46:10 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
root@RDE-1.3:~#
root@RDE-1.3:~#
root@RDE-1.3:~# curl -I http://179.188.3.54:8000
curl: (7) couldn't connect to host
PS:你添加了ALLOWED_HOSTS嗎? 默認值:[](空列表)
ALLOWED_HOSTS = [
'.example.com', # Allow domain and subdomains
'.example.com.', # Also allow FQDN and subdomains
]
表示此Django站點可以提供的主機/域名的字符串列表。 這是一種安全措施,可以通過使用偽造的HTTP主機標頭提交請求來防止攻擊者通過鏈接到惡意主機來中毒緩存和密碼重置電子郵件,即使在許多看似安全的Web服務器配置下也是如此。
此列表中的值可以是完全限定名稱(例如“www.example.com”),在這種情況下,它們將與請求的主機標頭完全匹配(不區分大小寫,不包括端口)。 以句點開頭的值可用作子域通配符:'。example.com'將匹配example.com,www.example.com和example.com的任何其他子域。 值'*'將匹配任何內容; 在這種情況下,您有責任提供自己的Host頭驗證(可能在中間件中;如果是這樣,則必須首先在MIDDLEWARE_CLASSES中列出此中間件)。
如果Host標頭(或X-Forwarded-Host,如果啟用了USE_X_FORWARDED_HOST)與此列表中的任何值都不匹配,則django.http.HttpRequest.get_host()方法將引發SuspiciousOperation。
當DEBUG為True或運行測試時,禁用主機驗證; 任何主人都會被接受。 因此,通常只需要將其設置為生產。
此驗證僅適用於get_host(); 如果您的代碼直接從request.META訪問Host頭,則您將繞過此安全保護。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.