基于SSL的虚拟主机使用Django和mod_wsgi的 [英] SSL based virtual host with django and mod_wsgi

查看:200
本文介绍了基于SSL的虚拟主机使用Django和mod_wsgi的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些网址可通过HTTP进行访问,而另一些将超过仅HTTP的安全Django的Web应用程序。我需要建立的虚拟主机/ mod_wsgi的配置在我的Apache的conf文件,使同一个Web应用程序可以通过这两个访问。我跟着这2个职位

I have a django web application in which some URLs are allowed to be accessed over http while others have to be over http-secure only. I need to set up the virtualHost/ mod_wsgi configuration in my apache conf file, so that the same web application can be accessed over both. I followed these 2 posts

  • How to force the use of SSL for some URL of my Django Application?
  • Django and SSL question

和具有以下配置我认为应该做的伎俩。

and have the following configuration which I think should do the trick.

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin me@mail.com
    DocumentRoot /var/www/html
    ServerName www.mydomain.com

    ErrorLog server-logs/error_log
    CustomLog server-logs/access_log common

    WSGIScriptAlias /test /var/www/my_app_root/apache/django.wsgi

    <Directory /var/www/my_app_root>
      Order allow,deny
      Allow from all
    </Directory>    
</VirtualHost>

NameVirtualHost *:443
<VirtualHost *:443>
    SSLEngine On
    SSLCertificateFile /etc/httpd/conf/ssl/mykey.crt
    SSLCertificateKeyFile /etc/httpd/conf/ssl/mykey.key

    ServerAdmin me@mail.com
    DocumentRoot /var/www/html
    ServerName www.mydomain.com

    ErrorLog server-logs/error_log
    CustomLog server-logs/access_log common

    WSGIScriptAlias /test /var/www/my_app_root/apache/django.wsgi

    <Directory /var/www/my_app_root>
      Order allow,deny
      Allow from all
    </Directory>
</VirtualHost>

然而,正在没有任何问题访问具有通过HTTP访问的URL,而那些必须通过HTTPS得到一个404 - 未找到错误。
我如果正在通过HTTP访问的视图,然后重定向到通过HTTPS取代HTTP的URL其中看到了装饰。因此,URL映射是正确的,因为我看到了重定向发生(这意味着视图被调用),但通过https,它得到404错误。

However, the urls which have to be accessed over http are being accessed without any issues, while those which have to be over https are getting a 404 - not found error. I have a decorator which sees if a view is being accessed over http and then redirects to a url with the http replaced by https. So the url-mapping is correct since I see the redirect happening (that means the view gets called) but over https, it gets 404 error.

我在Web服务器文档根目录的/ var / www / html等/ 这通过HTTPS工作正常第三方PHP应用程序。不知何故,该应用程序是没有面对过的任何问题HTTP或HTTPS。

I have a 3rd party php application in the webserver document root /var/www/html/ which works fine over https. Somehow, that application is not facing any issue over http or https.

我尝试以下


  • 试图在这两个虚拟主机相同的 WSGIProcessGroup 名守护进程模式的做法,但是这也不能工作了。

  • 我尝试添加听指挥443和Apache抱怨端口已绑定的错误。

  • Tried the Daemon mode approach with the same WSGIProcessGroup name in both virtual hosts, but that did not work out either.
  • I tried adding Listen 443 command, and apache complained of a port already bound error.

编辑:

由于您的所有意见,我探索的配置多一点,发现有这是得到在其定义*运行时间拉到子的conf文件:443虚拟主机(而没有足够的wsgiscript指令)。这就是为什么听443 被扔一个错误。而这也说明了404的URL通过HTTPS(在虚拟主机处理*:443无法解析URL)。现在,我修改了它,一切工作正常。在我原来的问题2堆栈溢出的职位提出的方法是完美的,正常工作。

Due to all your comments, I explored the configurations a bit more and found that there was a sub conf file which was getting pulled in at run time which was defining the *:443 virtual host (and did not have the wsgiscript directive). That's why the Listen 443 was throwing an error. And that also explains the 404 for the url over https (the virtualhost handling *:443 was unable to resolve that url). Now I modified it and everything is working fine. The approaches suggested in the 2 stack overflow posts in my original question are perfect and work correctly.

推荐答案

你有两个听80,并在你的apache2.conf提到听443? 可能有一定的帮助。

Do you have both "Listen 80" and "Listen 443" mentioned in your apache2.conf? This might be of some help.

这篇关于基于SSL的虚拟主机使用Django和mod_wsgi的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆