我在一个名为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()
谢谢大家的帮助!
Satchmo包括一个名为satchmo_store.shop.SSLMiddleware.SSLRedirect
的中间件,它可以自动重定向到站点的SSL/非SSL部分。如果希望通过SSL提供服务,则必须设置通过SSL提供的URL,否则中间件将重定向到非SSL页面。来自文档:
该中间件解决了重定向到SSL安全路径(以及从SSL安全路径重定向)的问题通过说明urls.py文件中应该保护哪些路径。若要保护路径,请添加additional view_kwarg'SSL':对于view_kwargs为True。
例如
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
文件中禁用该中间件。