2016-03-14 39 views
0

這是我的nginx的conf:如何設置nginx的配置(403頁禁止)通過OWASP安全測試

upstream django { 

    server 127.0.0.1:8001; 
} 

server { 
    listen  80; 
    server_name 127.0.0.1; 
    charset  utf-8; 

    #security 
    add_header X-Content-Type-Options "nosniff"; 
    add_header X-Frame-Options "DENY"; 
    add_header X-XSS-Protection "1; mode=block"; 

    location /static { 

     alias /usr/share/nginx/mysite/staticfiles; 

    } 

    location/{ 
     uwsgi_pass django; 
     include  /etc/nginx/uwsgi_params; 
    } 
} 

我的settings.py:

SECURE_BROWSER_XSS_FILTER = True 
SECURE_CONTENT_TYPE_NOSNIFF = True 
SESSION_COOKIE_SECURE = True 
SECURE_FRAME_DENY = True 

,但它仍然存在安全問題與靜態文件,我還應該設置什麼?

enter image description here

UPDATE

我發現作爲@LinnTroll說,看來nginx的403頁沒有安全保護。我應該如何設置?

enter image description here

回答

0

它不是Django的問題。 Nginx返回錯誤代碼(403)直接訪問/ static /等路徑,而指令add_header不適用於有錯誤代碼的響應。如果你使用nginx的版本> = 1.7.5,第三個參數「永遠」添加到add_header指令:

add_header X-Content-Type-Options "nosniff" always; 

如果你有nginx的版本低則1.7.5,我知道下面這個簡單的方法來解決你的問題:

  • nginx的更新到版本> = 1.7.5
  • 使指令autoindex on;你/靜態位置。 (警告:你靜態文件將可用於任何人,包括搜索引擎)你以前
  • 添加以下位置/靜態位置:

     
    location ~* ^/static.*/$ { 
        add_header X-Content-Type-Options "nosniff"; 
        # ... you other headers ... 
        add_header 'Content-Type' 'text/html; charset=UTF-8'; 
        return 200; 
    } 
    
+0

我的版本是1.6.3。我還沒有找到解決方案 – user2492364

+0

我應該如何處理403禁止? – user2492364

+0

我編輯了答案,檢查它 – LinnTroll