1

私はsatchmoと呼ばれるdjangoプロジェクトで奇妙な問題を抱えており、nginxとuwsgiでデプロイしています。

何が起こっているかというと、アプリケーションが応答し、nginx が停止してアプリケーションが応答しなくなるまで、https にリダイレクトしてから http にリダイレクトし、次に https にリダイレクトします。

これを理解するのを手伝ってください。ありがとうございました!

これは、nginx のサイトで利用可能な構成ファイルです。

server {
   listen 80;
   server_name miche.maumercado.com;
   rewrite      ^ https://$server_name$request_uri? permanent;
}

server {
        listen 443;
        charset utf-8;
        server_name miche.maumercado.com;
        ssl on;
        ssl_certificate /home/ubuntu/test.pem;
        ssl_certificate_key /home/ubuntu/cert-EO5rjY;
        access_log /home/ubuntu/logs/miche/nginx/access.log;
        error_log /home/ubuntu/logs/miche/nginx/error.log;
        client_max_body_size 100m;
        location ^~ /static/ {
                alias /home/ubuntu/django-projects/miche_store/static-collect/;
                expires max;
        }

        location ^~ /media/ {
                alias /home/ubuntu/django-projects/miche_store/media/;
                expires max;
        }

        location / {
                uwsgi_pass unix:/tmp/uwsgi_miche.sock;
                include /etc/nginx/uwsgi_params;
        }

}

これは、/etc/init の uwsgi.conf ファイルです。

# file: /etc/init/uwsgi_miche.conf
description "uWSGI starter"

start on (local-filesystems and runlevel [2345])
stop on runlevel [016]

respawn

# home - is the path to our virtualenv directory
# pythonpath - the path to our django application
# module - the wsgi handler python script

exec /home/ubuntu/ve/miche_store/bin/uwsgi \
--uid ubuntu \
--pythonpath /home/ubuntu/django-projects/miche_store \
-H /home/ubuntu/ve/miche_store \
--socket /tmp/uwsgi_miche.sock \
--chmod-socket 644 \
--module wsgi \
--logdate \
--optimize 2 \
--processes=6 \
--max-requests=5000 \
--master \
--vacuum \
--logto /home/ubuntu/logs/miche/uwsgi.log

そして、私の wsgi.py ファイルは次のとおりです。

import os
import sys
import site

site.addsitedir('/home/ubuntu/ve/miche_store/lib/python2.6/site-packages')
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
sys.path.append(os.path.join(os.path.realpath(os.path.dirname(__file__)), '../'))

os.environ['DJANGO_SETTINGS_MODULE'] = 'miche_store.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

ご協力ありがとうございました!

4

1 に答える 1

3

Satchmo にはsatchmo_store.shop.SSLMiddleware.SSLRedirect、サイトの SSL/非 SSL 部分へのリダイレクトを自動的に行う と呼ばれるミドルウェアが含まれています。URL を SSL 経由で提供する場合は、URL を SSL 経由で提供するように設定する必要があります。そうしないと、ミドルウェアが非 SSL ページにリダイレクトされます。ドキュメントから:

このミドルウェアは、urls.py ファイルでどのパスを保護する必要があるかを示すことにより、SSL で保護されたパスへの (およびからの) リダイレクトの問題に答えます。パスを保護するには、追加の view_kwarg 'SSL':True を view_kwargs に追加します。

例えば

urlpatterns = patterns('some_site.some_app.views',
    (r'^test/secure/$','test_secure',{'SSL':True}),
     )

'SSL':False または 'SSL' の kwarg が指定されていないすべてのパスは、安全でないパスにルーティングされます。

例えば

urlpatterns = patterns('some_site.some_app.views',
    (r'^test/unsecure1/$','test_unsecure',{'SSL':False}),
    (r'^test/unsecure2/$','test_unsecure'),
     )

あなたの場合、SSL 経由でサイト全体を提供しているので、おそらくsettings.pyファイルでそのミドルウェアを無効にすることができます。

于 2012-08-29T17:32:37.463 に答える