安装SSL后在Ubuntu 18.04上使用Apache2的Django站点无法正常工作

时间:2019-02-11 02:07:45

标签: django ssl apache2 mod-wsgi certbot

我正在尝试使用mode_wsgi在Apache2上的Apache2上的Ubuntu 18.04上部署Djang(1.10)应用程序,该站点在设置SSL之前运行良好,但是当我使用{{1 }}不再加载。

这是我的配置:

项目文件夹路径:

certbot

/home/abdul 配置:

Http

此处的<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. ServerName www.orderfetchers.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf Alias /static /home/abdul/Fetchors/static <Directory /home/abdul/Fetchors/static> Require all granted </Directory> Alias /media /home/abdul/Fetchors/media <Directory /home/abdul/Fetchors/media> Require all granted </Directory> <Directory /home/abdul/Fetchors/Fetchors> <Files wsgi.py> Require all granted </Files> </Directory> #WSGIScriptAlias / /home/abdul/Fetchors/Fetchors/wsgi.py #WSGIDaemonProcess django_app python-path=/home/abdul/Fetchors python-home=/home/abdul/Fetchors/venv #WSGIProcessGroup django_app RewriteEngine on RewriteCond %{SERVER_NAME} =www.orderfetchers.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet 配置:

Https

1 个答案:

答案 0 :(得分:1)

tl; dr::检查防火墙(端口443),并使用有关配置的在线教程(如下)。


好吧,所以我遇到了与您完全相同的错误-我的网站在Ubuntu 80上的Apache2和Django 1.10的端口80上运行良好,当我按照LetsEncrypt的指南进行操作时,我的网站将被永久载入在超时之前。我假设您帖子中的问题是如何阻止您的网站暂停并真正加载它。

就我而言,我很幸运,因为我只是一个白痴,忘记了为我的Ubuntu机器打开AWS Security Group上的端口443。但是,我还有一些其他配置可以帮助您:

settings.py

# SSL support
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

# session expire at browser close
SESSION_EXPIRE_AT_BROWSER_CLOSE = True

# wsgi scheme
os.environ['wsgi.url_scheme'] = 'https'

wsgi.py

os.environ['HTTPS'] = "on"

这些配置是在这些参考站点的帮助下找到并编译的(可能也有帮助):

https://simpleisbetterthancomplex.com/tutorial/2016/05/11/how-to-setup-ssl-certificate-on-nginx-for-django-application.html

https://www.pdxpixel.com/blog/2014/02/04/setting-up-django-site-ssl-apache-mod_wsgi-mod_ssl/

https://docs.djangoproject.com/en/dev/topics/security/#ssl-https

如果不对您的系统有更多的了解,很难更精确地提供帮助,但这是我发现有用的,因此希望对您有所帮助。