2015-02-24 120 views
0

我做我自己的配置爲我的Web服務器,如果我通過IP訪問我的網站,一切都可以正常使用 - http://179.188.3.54壞請求(400)和Django

我沒有改變我的域名還沒有,我修改/ 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 ^()(.*)$; 
} 
} 

我不知道什麼可以是錯誤的,據我知道我沒有改變任何東西。有任何想法嗎?

回答

2

意味着什麼呢proxy_pass的http:// 0.0.0.0:8000 /?也許必須有127.0.0.1或179.188.3.54

並檢查您的端口proxy_pass

[email protected]:~# 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 

[email protected]:~# 
[email protected]:~# 
[email protected]:~# 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的。值'*'將匹配任何東西;在這種情況下, 你有責任提供自己的主機 頭的驗證(也許在中間件;若有此中間件必須在MIDDLEWARE_CLASSES上市 第一)。

如果主機頭(或X轉發,主機如果USE_X_FORWARDED_HOST是 啓用)不匹配,在此列表中的任何值,則 django.http.HttpRequest.get_host()方法將引發 SuspiciousOperation。

當DEBUG爲True或運行測試時,主機驗證被禁用; 任何主機都將被接受。因此通常只需要將其設置爲 即可生產。

此驗證只適用於通過get_host();如果您的代碼直接從request.META訪問 主機頭,那麼您將繞過此安全保護措施 。

+0

我試了兩個,我仍然有同樣的問題.. – Lara 2015-02-24 13:55:28

+0

更新與捲曲輸出。這就像你有錯誤的端口。你如何運行Django? python manage.py runserver 0.0.0。0:8000 – 2015-02-24 15:48:11

+0

我加了ALLOWED_HOSTS鏈接 – 2015-02-24 15:54:52