分类 云计算 下的文章

在 Windows 2008 R2 64位系统为 wampserver apache 不同网站配置不同SSL证书(SNI)

有云友 提问,想为 wampserver 套件里的 apache 配置SSL证书安全访问。

环境:Windows 2008 R2 64位中文系统 , wampserver2.5-Apache-2.4.9-Mysql-5.6.17-php5.5.12-64b

过程:

1.安装好wamp,本例是安装到 C:\wamp 且测试可用,启用 mod_ssl模块
bbs-aliyun-dongshan3-305369-1.png

bbs-aliyun-dongshan3-305369-2.png

2.将下载好的证书放到 apache 目录下,如我将 yun.anqun.org 的SSL证书保存在 C:\wamp\bin\apache\apache2.4.9\conf\ssl\yun\ 里

3.编辑 httpd.conf 配置文件(C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf),将约在530行的,关于ssl配置的文件启用;
bbs-aliyun-dongshan3-305369-3.png

4.编辑 httpd-ssl.conf 文件,按实际情况配置虚拟主机的ssl内容,如本例里的 yun.anqun.org 及 portal.anqun.org 的简要配置内容如下(如果apache未加载mod_socache_shmcb块,还需要先注释掉SSLSessionCache的设置,约在第73行):
bbs-aliyun-dongshan3-305369-4.png

5.保存配置文件后,重启apache,在Chrome浏览器里测试访问,显示结果正常
bbs-aliyun-dongshan3-305369-5.png

bbs-aliyun-dongshan3-305369-6.png

在 Debian 8 系统 为 tomcat8 配置https站点访问

在“云栖问答 ”里看到有人提到在tomcat里配置https访问时,可能会遇到问题,所以写此帖。

环境:“经典网络”类型ECS,Debian 8系统,Tomcat 8,JDK 1.7

过程:

1.安装相应的软件或组件,
apt-get install default-jdk tomcat8 tomcat8-examples
bbs-aliyun-dongshan3-305110-1.png

2.将在阿里云申请的,适合tomcat的证书文件上传到合适的目录,如本例是保存在:/etc/tomcat8/cert/213949634960268.pfx

3.编辑 tomcat 的配置文件 /etc/tomcat8/server.xml ,添加相应的https访问配置内容,如本例约在第92号添加了:

<Connector port="8443"
    protocol="HTTP/1.1"
    SSLEnabled="true"
    scheme="https"
    secure="true"
    keystoreFile="/etc/tomcat8/cert/213949634960268.pfx"
    keystoreType="PKCS12"
    keystorePass="213949634960268"
    clientAuth="false"
    SSLProtocol="TLSv1+TLSv1.1+TLSv1.2"
    />
````
其中关键是port,keystoreFile 和 keystorePass,请根据自己的实际情况修改。因为在Debian里的tomcat默认运行账户是tomcat8,是无权限直接使用443端口的,所以本例的port用8443 
![bbs-aliyun-dongshan3-305110-2.png][2]
 
4.重启tomcat服务 
systemctl restart tomcat8
 
6.在火狐浏览器访问,如 https://yun.anqun.org:8443,测试正常 
![bbs-aliyun-dongshan3-305110-3.png][3] 
 
参考:  
* https://tomcat.apache.org/tomcat-8.0-doc/ssl-howto.html 
* https://confluence.atlassian.com/confkb/permission-denied-error-when-binding-a-port-290750651.html 


  [1]: https://liujia.anqun.org/usr/uploads/2019/06/09/81045930862347.png
  [2]: https://liujia.anqun.org/usr/uploads/2019/06/09/81045765975983.png

在CentOS 7 系统设置使用公钥登录(publickey)

看到云友“鱼鱼鱼鱼啊 ”想设置公钥登录到CentOS系统,所以写此帖。

环境:经典网络类型的ECS,CentOS 7.2系统,远程ssh登录软件为MobaXterm 9.4

过程:

1.在 MobaXterm 软件的 Tools 菜单里点周 MobaKeyGen,生成公/私钥对
bbs-aliyun-dongshan3-304996-1.png

2.点击 Generate 按钮,在生成过程中,会提示您移动鼠标,随机生成创建
bbs-aliyun-dongshan3-304996-2.png

bbs-aliyun-dongshan3-304996-3.png

3.将生成的公钥(public key)复制,粘贴到 ~/.ssh/authorized_keys 中(可先通过mkdir ~/.ssh/ 创建好目录,再vi ~/.ssh/authorized_keys 粘贴 ),请注意要复制完整
bbs-aliyun-dongshan3-304996-4.png

bbs-aliyun-dongshan3-304996-5.png

4.点击 Save private key,保存好私钥
bbs-aliyun-dongshan3-304996-6.png

5.执行以下命令,设置公钥文件和目录的权限
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

6.修改 /etc/ssh/sshd_config 的配置内容,将其中的 PasswordAuthentication 更改为 no
bbs-aliyun-dongshan3-304996-7.png

7.运行 systemctl restart sshd 重启 sshd 服务

8.在MobaXterm的会话管理里,在 Use private key 里选择保存好的私钥
bbs-aliyun-dongshan3-304996-8.png

9.登录测试,成功
bbs-aliyun-dongshan3-304996-9.png

参考:

在 CentOS 6 系统 为 apache 不同网站配置不同SSL证书(SNI)

云友“fjfyfh ”希望能看到在CentOS 6系统里为apache站点配置https的例子,所以写此帖。

环境:CentOS 6.8 64位,apache 2.2

目的:为两个站点(yun.anqun.org, portal.anqun.org)配置https访问。

前提:在阿里云申请下载了相应的SSL证书。

过程:

1.执行以下的命令,安装好apache及mod_ssl模块
yum install httpd mod_ssl
bbs-aliyun-dongshan3-304549-1.png

bbs-aliyun-dongshan3-304549-2.png

2.将站点的SSL证书上传到相应的目录,如本例的 yun_anqun_org.pem 上传到了 /etc/pki/tls/certs/ 目录,yun_anqun_org.key 上传到了 /etc/pki/tls/private/ 目录,需要留意,key文件仅root账户可读写
bbs-aliyun-dongshan3-304549-3.png

3.编辑站点SSL配置文件, /etc/httpd/conf.d/ssl.conf ,如本例,删除了原有默认的SSL 虚拟站点配置内容,增加了以下的SSL 虚拟站点内容:

##
## SSL Virtual Host Context
##
NameVirtualHost *:443
<VirtualHost *:443>
  ServerName yun.anqun.org
  DocumentRoot /var/www/html/yun.anqun.org
  SSLEngine on
  SSLProtocol all -SSLv2
  SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
  SSLCertificateFile "/etc/pki/tls/certs/yun_anqun_org.pem"
  SSLCertificateKeyFile "/etc/pki/tls/private/yun_anqun_org.key"
</VirtualHost>
<VirtualHost *:443>
  ServerName portal.anqun.org
  DocumentRoot /var/www/html/portal.anqun.org
  SSLEngine on
  SSLProtocol all -SSLv2
  SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
  SSLCertificateFile "/etc/pki/tls/certs/portal_anqun_org.pem"
  SSLCertificateKeyFile "/etc/pki/tls/private/portal_anqun_org.key"
</VirtualHost>

bbs-aliyun-dongshan3-304549-4.png

4.重启apache服务后,在火狐浏览器浏览测试,显示正常
bbs-aliyun-dongshan3-304549-5.png

bbs-aliyun-dongshan3-304549-6.png

参考:https://wiki.apache.org/httpd/NameBasedSSLVHostsWithSNI

为阿里云ECS(CentOS 5)配置IPv6隧道地址

云友“ap6554s5w”希望 能在CentOS 5系统里配置IPv6地址,所以写此帖。

环境:ECS“经典网络”类型(网友“ifaceparty”提醒:如果是“专有网络”,需要将HE配置隧道地址命令中的IPv4地址修改为ECS实例的内网地址),CentOS 5.11 64位系统。

注意:如是苹果APP上架申请因无法IPv6-only访问被拒,请重点检查APP代码,苹果公司的参考文档并没有要求APP服务需要有IPv6地址:https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/UnderstandingandPreparingfortheIPv6Transition/UnderstandingandPreparingfortheIPv6Transition.html

1.CentOS 5.11 64位系统,默认没有启用IPv6地址

2.编辑 /etc/sysctl.conf 文件,将其中三条禁用IPv6的设置更改为:

net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.lo.disable_ipv6 = 0
````
 
3.编辑文件,/etc/modprobe.d/disable_ipv6.conf,将其中的两行都注释掉:[/code] 

alias net-pf-10 off

options ipv6 disable=1

![bbs-aliyun-dongshan3-304532-1.png][1]
 
4.编辑文件,/etc/sysconfig/network,将其中的 NETWORKING_IPV6=no 改为 NETWORKING_IPV6=yes 
NETWORKING_IPV6=yes
![bbs-aliyun-dongshan3-304532-2.png][2] 
 
5.重启系统,以让更改生效。系统重启后,运行 ifconfig 命令,可以看到IPv6的地址  
 
7.执行 HE 隧道地址配置例子中的 Linux-net-tools 命令,如本例是: 

ifconfig sit0 up
ifconfig sit0 inet6 tunnel ::216.218.221.6
ifconfig sit1 up
ifconfig sit1 inet6 add 2001:470:18:401::2/64
route -A inet6 add ::/0 dev sit1

![bbs-aliyun-dongshan3-304532-3.png][3] 
 
8.安装 nginx 后,启动 nginx ,可以看到在IPv6(:::80)里监听使用了  
![bbs-aliyun-dongshan3-304532-4.png][4] 
 
9.在其它IPv6的系统上,用 curl 测试 IPv6 域名和IP地址站点内容,正常。实践中,访问IPv6的网站内容可能较慢,这可能是因为提供隧道地址的网络与国内连接较慢 

curl 'http://yun.anqun.org' -so - | grep -iPo '(?<=)(.*)(?=)'
curl [2001:470:18:401::2] -so - | grep -iPo '(?<=)(.*)(?=)'
curl -6 'http://ipv6.anqun.org' -so - | grep -iPo '(?<=)(.*)(?=)'

![bbs-aliyun-dongshan3-304532-5.png][5] 
 
参考:https://tunnelbroker.net/ 


  [1]: https://liujia.anqun.org/usr/uploads/2019/06/09/802672251359026.png
  [2]: https://liujia.anqun.org/usr/uploads/2019/06/09/80268753090719.png
  [3]: https://liujia.anqun.org/usr/uploads/2019/06/09/80268887271176.png
  [4]: https://liujia.anqun.org/usr/uploads/2019/06/09/802682848492264.png