阿帕奇&x2B;django+;mod_wsgi到https的转换一直回到http
我有一个使用Apache和mod_wsgi的django(satchmo)站点已经运行了好几年了。到目前为止,它只提供http服务,我正在尝试将整个站点转换为https。我有一个签名的ssl证书,我相信这是好的 根据我对文档的理解,我已经调整了我的Apache配置 当我尝试使用https连接到站点时,浏览器在端口443上连接良好,Apache服务器响应正确的ssl证书,然后是TLS密钥交换等(根据我在Wire Shark中看到的)。在这一点上,一切看起来都很好,没有错误。但是 一旦建立了ssl连接,浏览器就会在与端口80(即HTTP)的新TCP连接中启动“GET/HTTP/1.1”。它好像对已经存在的https连接一无所知 有可能是django的错吗?我根本没有更改django配置,因为我觉得只有Apache需要知道它?(我不使用nginx-Apache处理所有内容。) 我无法“看到”ssl对话中发生了什么,但django大概是在告诉浏览器客户端以某种方式连接端口80?可能吗 为了简单起见,当您连接到http时,我现在有一个普通的index.html页面,并且我已经将所有django&mod_wsgi移到了端口443。如果我直接连接到http地址,我会得到简单的索引页,没有问题 当我尝试连接到https地址时,浏览器实际上被重定向到index.html页面。(不过,我在Apache中没有任何重定向或重写命令。) 以下是我的Apache配置:阿帕奇&x2B;django+;mod_wsgi到https的转换一直回到http,django,apache,ssl,Django,Apache,Ssl,我有一个使用Apache和mod_wsgi的django(satchmo)站点已经运行了好几年了。到目前为止,它只提供http服务,我正在尝试将整个站点转换为https。我有一个签名的ssl证书,我相信这是好的 根据我对文档的理解,我已经调整了我的Apache配置 当我尝试使用https连接到站点时,浏览器在端口443上连接良好,Apache服务器响应正确的ssl证书,然后是TLS密钥交换等(根据我在Wire Shark中看到的)。在这一点上,一切看起来都很好,没有错误。但是 一旦建立了ssl连
<VirtualHost *:80>
ServerName demo.pasta.co.za
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
DocumentRoot /var/www/http_site
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
SSLCertificateFile /etc/ssl/private/pasta.co.za.crt
SSLCertificateKeyFile /etc/ssl/private/pasta.co.za.key
SSLCertificateChainFile /etc/ssl/private/root_bundle.crt
ServerName demo.pasta.co.za
Alias /favicon.ico /usr/local/django/pasta/static/favicon.ico
Alias /robots.txt /usr/local/django/pasta/static/robots.txt
AliasMatch ^/([^/]*\.css) /usr/local/django/pasta/store/static/$1
WSGIDaemonProcess demo.pasta.co.za processes=2 threads=25 display-name=%{GROUP}
WSGIProcessGroup demo.pasta.co.za
WSGIScriptAlias / /usr/local/django/pasta/apache/django.wsgi
<Directory /usr/local/django/pasta/apache>
Order allow,deny
Allow from all
</Directory>
Alias /static/admin/ /usr/share/pyshared/django/contrib/admin/static/admin/
Alias /static/images/ /usr/local/django/pasta/store/static/images/
Alias /static/ /usr/local/django/pasta/store/static/
Alias /media/ /usr/local/django/pasta/store/static/
<Directory /usr/local/django/pasta/store/static>
Order deny,allow
Options -Indexes
Allow from all
</Directory>
<Directory /usr/share/pyshared/django/contrib/admin/static/admin>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
这里有几十个这样的例子,人们或多或少地用我上面的东西来完成我想要做的事情
我错过了什么?我觉得我遗漏了一些非常明显的东西
我让Debian稳定运行django v1.4.5 python v2.7.3和apache v2.2.22以及mod wsgi v3.3-4
非常感谢 米帕迪接受的答案
Satchmo包括一个称为Satchmo_store.shop.SSLMiddleware.SSLRedirect的中间件,它自动重定向到站点的SSL/非SSL部分。如果希望通过SSL提供服务,则必须设置要通过SSL提供服务的URL,否则中间件将重定向到非SSL页面。从文档中:
This middleware answers the problem of redirecting to (and from) a SSL secured path by stating what paths should be secured in urls.py file. To secure a path, add the additional view_kwarg 'SSL':True to the view_kwargs.
For example
urlpatterns = patterns('some_site.some_app.views',
(r'^test/secure/$','test_secure',{'SSL':True}),
)
All paths where 'SSL':False or where the kwarg of 'SSL' is not specified are routed to an unsecure path.
For example
urlpatterns = patterns('some_site.some_app.views',
(r'^test/unsecure1/$','test_unsecure',{'SSL':False}),
(r'^test/unsecure2/$','test_unsecure'),
)
在您的情况下,由于您通过SSL为整个站点提供服务,您可能只需在settings.py文件中禁用该中间件即可
(根据我的经验,您需要在一些文件中更改许多urlpatterns。)使用nginx和uwsgi部署,这样就不那么麻烦了,谢谢doniyor,但我更愿意了解问题所在。
This middleware answers the problem of redirecting to (and from) a SSL secured path by stating what paths should be secured in urls.py file. To secure a path, add the additional view_kwarg 'SSL':True to the view_kwargs.
For example
urlpatterns = patterns('some_site.some_app.views',
(r'^test/secure/$','test_secure',{'SSL':True}),
)
All paths where 'SSL':False or where the kwarg of 'SSL' is not specified are routed to an unsecure path.
For example
urlpatterns = patterns('some_site.some_app.views',
(r'^test/unsecure1/$','test_unsecure',{'SSL':False}),
(r'^test/unsecure2/$','test_unsecure'),
)