openstack云平台访问安全http->https

 

UbuntuHTTPS配置非常简单,对大部分用户而言,使用普通的自签名证书,只需按照步骤进行就可以了,无需了解密钥、证书的更多知识,更深的背景知识还有RSA算法、DES算法、X509规范、CA机构...等等,随便哪个方向都够学习一阵子的,所幸的是有了OpenSSLOpenSSH等这些开源免费的软件,把很多底层的算法、规范都集成了,对上层应用而言,只需一二三操作即可,至多到官网去查查一些特殊的命令集。

 

Apache2openssl确认已经安装,开启ssl模块

sudo a2enmod ssl,这条命令相当于

sudo ln -s /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled

sudo ln -s /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-enabled

如果没有a2enmod指令,也可直接在apache2.conf中设置SSL模块加载:LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so

 

创建证书,创建证书有两种:一种是自签名证书,另外一种是第三方CA机构签名证书。第一种随便使用,只是没有经过官方认可的机构认证而已,后一种则是正规的签名证书,有发证机构签名。其实很多所谓的大网站上使用的SSL证书,一样都是自签名的,主要是因为这个证书只做为在线验证使用,保证传输数据安全即可,不过使用这种证书,对常规浏览器和一些软件而言,一般均会弹出警告,让你确认这个签名证书的有效性。正规签名证书也不过只是多了一重保障而已,而且浏览器、软件等可以自己鉴别。

我们选用自签名证书,使用openssl命令创建:

sudo openssl req -x509 -newkey rsa:1024 -keyout apache.pem -out apache.pem -nodes -days 999

创建完成后,当前目录下有个apache.pem文件,已经包含密钥和证书。可以把这个证书拷贝到/etc/ssl/private/:

mv apache.pem /etc/ssl/apache.pem

 

HTTPSSSL)配置,编辑Apache端口配置(/etc/apache2/ports.conf),加入443端口(SSL缺省使用):

Listen 80

Listen 443

例如:

Listen 80

 

<IfModule ssl_module>

        Listen 443

</IfModule>

 

<IfModule mod_gnutls.c>

        Listen 443

</IfModule>

 

修改配置文件openstack-dashboard.conf

WSGIScriptAlias /horizon /usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi

WSGIDaemonProcess horizon user=horizon group=horizon processes=3 threads=10

WSGIProcessGroup horizon

Alias /static /usr/share/openstack-dashboard/openstack_dashboard/static/

<Directory /usr/share/openstack-dashboard/openstack_dashboard/wsgi>

  Order allow,deny

  Allow from all

</Directory>

 

<VirtualHost *:80>

ServerName localhost

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

</IfModule>

<IfModule !mod_rewrite.c>

RedirectPermanent / http://www.kylinos.cn

</IfModule>

</VirtualHost>

 

<VirtualHost *:443>

ServerName localhost

 

SSLEngine on

# Remember to replace certificates and keys with valid paths in your environment

SSLCertificateFile    /etc/ssl/private/apache.pem

#SSLCertificateFile /etc/apache2/SSL/openstack.example.com.crt

#SSLCACertificateFile /etc/apache2/SSL/openstack.example.com.crt

#SSLCertificateKeyFile /etc/apache2/SSL/openstack.example.com.key

SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown

# HTTP Strict Transport Security (HSTS) enforces that all communications

# with a server go over SSL. This mitigates the threat from attacks such

# as SSL-Strip which replaces links on the wire, stripping away https prefixes

# and potentially allowing an attacker to view confidential information on the

# wire

#Header add Strict-Transport-Security "max-age=15768000"

WSGIScriptAlias / /usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi

#WSGIDaemonProcess horizon user=www-data group=www-data processes=3 threads=10

Alias /static /usr/share/openstack-dashboard/openstack_dashboard/static/

<Directory /usr/share/openstack-dashboard/openstack_dashboard/wsgi>

# For Apache http server 2.2 and earlier:

Order allow,deny

Allow from all

# For Apache http server 2.4 and later:

# Require all granted

</Directory>

</VirtualHost>

 

修改配置文件/etc/openstack-dashboard/local_settings.py

LOGIN_URL = '/horizon/auth/login/'

LOGOUT_URL = '/horizon/auth/logout/'

LOGIN_REDIRECT_URL = '/horizon'

改为

LOGIN_URL = '/auth/login/'

LOGOUT_URL = '/auth/logout/'

LOGIN_REDIRECT_URL = '/'

 

 

 

 

注意:现在所有的内容链接都必须指向https,如果网站上的一些内容(像图片或者css文件等)仍旧指向http链接的话,你会在浏览器中得到一个警告,要修复这个问题,请确保每个链接都指向了https

 

在你的网站上重定向HTTP请求到HTTPS

 

如果你希望重定向常规的HTTP请求到HTTPS,添加下面的文本到你希望修改的虚拟主机,或者如果希望给服务器上所有网站都添加的话就加入到apache.conf中:

 

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值