2016-02-12 39 views
0

我使用Nginx(1.8.1)在VPS中部署Ghost(0.7.6)。爲了使儀表板和登錄頁面安全,我強制要求在訪問此類頁面時使用HTTPS(例如/ghost頁面)。但是,對於任何其他頁面的請求(例如訪問Ghost博客本身),我想強制它使用HTTP。 Ghost正在收聽127.0.0.1:2368ERR_TOO_MANY_REDIRECTS同時使用HTTP和HTTPS設置Ghost + Nginx

奇怪的是,結果並不像我所期待的:我每次訪問我的博客(假設URL是a.b),它說,我的網站有ERR_TOO_MANY_REDIRECTS,它http://a.bhttps://a.b(或http://a.b/signinhttps://a.b/signin之間重定向)。但是,當我訪問管理控制檯(https://a.b/ghosthttp://a.b/ghost)時,它按預期行事(沒有錯誤,正確重定向以使用HTTPS)。

任何幫助?

我的Nginx的配置:

# Configuration for http://a.b 
server { 
    listen 80; 
    server_name a.b; 
    location ^~ /ghost { # /ghost should be accessed securely 
     return 301 https://$host$request_uri; 
    } 
    location/{ 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header HOST $host; 
     proxy_set_header X-NginX-Proxy true; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_pass http://127.0.0.1:2368; 
    } 
} 

# Configuration for http://a.b 
server { 
    listen 443 ssl; 
    server_name a.b; 
    ssl_certificate ...; 
    ssl_certificate_key ...; 
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_prefer_server_ciphers on; 
    ssl_ciphers '...'; 

    location ^~ /ghost { # /ghost should be accessed securely 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header HOST $host; 
     proxy_set_header X-NginX-Proxy true; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_pass http://127.0.0.1:2368; 
    } 
    location/{ # Force to use HTTP 
     return 301 http://$host$request_uri; 
    } 
} 

任何形式的幫助,將不勝感激:')

+0

爲什麼不直接啓用HTTPS整個網站上?如果你使用spdy或者http2,那麼對於你來說,維護更簡單,對你更安全,更快。 – Tom

回答

0

https://github.com/TryGhost/Ghost/issues/2796

location ^~ /ghost { # /ghost should be accessed securely 
    proxy_set_header X-Forwarded-Proto $scheme; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header HOST $host; 
    proxy_set_header X-NginX-Proxy true; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_pass http://127.0.0.1:2368; 
} 
相關問題