【问题标题】:satchmo nginx redirect to https then to http and backsatchmo nginx 重定向到 https 然后到 http 并返回
【发布时间】:2012-08-24 09:04:35
【问题描述】:

我在一个名为 satchmo 的 django 项目中遇到了一个奇怪的问题,我正在使用 nginx 和 uwsgi 进行部署。

发生的事情是应用程序确实响应并且它重定向到 https,然后重定向到 http 并返回到 https,直到 nginx 停止并且应用程序永远不会响应。

帮我弄清楚这一点。谢谢!

这是我的 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()

感谢大家的帮助!

【问题讨论】:

    标签: python django uwsgi satchmo


    【解决方案1】:

    Satchmo 包含一个名为 satchmo_store.shop.SSLMiddleware.SSLRedirect 的中间件,它会自动重定向到网站的 SSL/非 SSL 部分。如果您希望通过 SSL 提供 URL,则必须设置通过 SSL 提供的 URL,否则中间件将重定向到非 SSL 页面。来自文档:

    这个中间件解决了重定向到(和从)SSL 安全路径的问题 通过说明应该在 urls.py 文件中保护哪些路径。要保护路径,请添加 附加 view_kwarg 'SSL':对 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 文件中禁用该中间件。

    【讨论】:

      猜你喜欢
      • 2011-03-29
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      • 2017-09-20
      相关资源
      最近更新 更多