2011-01-07 2 views
0

Django + nginx + wsgi + sslのいくつかの例を追ってきましたが、動作させることができません。私は単に私のブラウザで私が接続できないエラーを取得します。django + nginx + wsgiでSSLを動作させるのに問題がある

私はホストから2つのウェブサイトを実行しています。設定ファイルは、IPアドレス、サーバー名、およびディレクトリを除いて同一です。

どちらもSSLを使用しない場合、正常に動作します。私が443のうちの1つで聴いてみると、どちらにも接続できません。

私の設定ファイルは以下の通りです。ご意見をいただければ幸いです。

server{ 
listen xxx.xxx.xxx.xxx:80; 
server_name sub.domain.com; 

access_log /home/django/logs/nginx_customerdb_http_access.log; 
error_log /home/django/logs/nginx_customerdb_http_error.log; 

location/{ 
    proxy_pass http://127.0.0.1:8080; 
    proxy_redirect   off; 
    proxy_set_header  Host   $host; 
    proxy_set_header  X-Real-IP  $remote_addr; 
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
    client_max_body_size 10m; 
    client_body_buffer_size 128k; 
    proxy_connect_timeout 90; 
    proxy_send_timeout  90; 
    proxy_read_timeout  90; 
    proxy_buffers   32 4k; 
} 

location /site_media/ { 
    alias /home/django/customerdb_site_media/; 
} 

location /admin-media/ { 
    alias /home/django/django_admin_media/; 
} 
} 

server{ 
listen xxx.xxx.xxx.xxx:443; 
server_name sub.domain.com; 

access_log /home/django/logs/nginx_customerdb_http_access.log; 
error_log /home/django/logs/nginx_customerdb_http_error.log; 

ssl on; 
ssl_certificate sub.domain.com.crt; 
ssl_certificate_key sub.domain.com.key; 
ssl_prefer_server_ciphers on; 


location/{ 
    proxy_pass    http://127.0.0.1:8080; 
    proxy_redirect   off; 
    proxy_set_header  Host   $host; 
    proxy_set_header  X-Real-IP  $remote_addr; 
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header  X-Forwarded-Protocol https; 
    client_max_body_size 10m; 
    client_body_buffer_size 128k; 
    proxy_connect_timeout 90; 
    proxy_send_timeout  90; 
    proxy_read_timeout  90; 
    proxy_buffers   32 4k; 
} 

location /site_media/ { 
    alias /home/django/customerdb_site_media/; 
} 

location /admin-media/ { 
    alias /home/django/django_admin_media/; 
} 
} 


<VirtualHost *:8080> 
ServerName xxx.xxx.xxx.xxx 
ServerAlias xxx.xxx.xxx.xxx 

LogLevel warn 
ErrorLog /home/django/logs/apache_customerdb_error.log 
CustomLog /home/django/logs/apache_customerdb_access.log combined 

WSGIScriptAlias//home/django/customerdb/apache/django.wsgi 
WSGIDaemonProcess customerdb_wsgi processes=4 threads=5 
WSGIProcessGroup customerdb_wsgi 

SetEnvIf X-Forwarded-Protocol "^https$" HTTPS=on 

</VirtualHost> 

UDPATE:ホスト上に2つのサイト(別々のIP上)が存在することが問題です。他のサイトを削除した場合は、上記の設定がほとんど機能します。そうすることで別の問題が発生します。クロムは、一部のコンテンツが暗号化されていないとセキュリティで保護されたサイトを受け入れません。

答えて

0

80でリッスンするサーバーをhttpsに書き換えるように変更し、他のすべてのディレクティブを削除しました。 [これは実際にコメントをする必要があります...]

2

はまた、そうでない場合は、あなたのhttpsリンクはHTTPにリダイレクトされます、接続が安全であるジャンゴに示すために

proxy_set_header X-Forwarded-Protocol $scheme

を設定する必要があります、それは悪いです。

実際にhttpのときはhttphttpsのときはhttpsに設定されます。

+0

Django 1.4+の対応設定については、https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-headerを参照してください。 –

関連する問題