服务器端的https登陆设置请看
http://baalchina.nau.edu.cn/2008/08/nginx-https-rewrite/
大概了解下用到的模板,包括header.htm,footer.htm,以及logging.htm。另外,登陆成功/失败使用的是showmessage.htm模板。
首先,以header.htm和footer.htm为基础,新建header_ssl.htm以及footer.htm,在logging.php中将相应引用模板的位置修改为引用新建的ssl模板。
接下来修改对应模板。这个稍有点复杂,需要一点点调试。去掉所有的外联的图片、外联的css以及js---通过将他们修改为文件内部引用。
其中:
common.js不需要。可以去掉。
css中,注意这个:
.mainbox
他引用了一个
{HEADERBGCODE};
变量。这个其实就是一个background的图片。所以需要把这个删除。否则还是会提示“存在不安全的内容”
其他的就不多说了。包括footer中的连接等。很多,需要自己一个个去调试。
另外是showmessage模板。这个用于登陆成功、失败之后的跳转页面。
首先修改global.func.php,找到showmessage这个函数,然后复制,将函数名改成showmessagessl,或者随便其他什么名字。
将函数中用到的模板修改为showmessgae_ssl
修改logging.php,将所有的showmessage修改为showmessagessl。
修改showmessage_ssl模板,将header和footer用前面的header_ssl和footer_ssl代替。
基本搞定。
现在还是有一个提示,这个提示是登陆成功、失败之后访问/uc/api.php造成的。这个问题还需要考虑下怎么做。感觉在服务器上处理比较方便。
-
首先需要升级OpenSSL和OpenSSH。后者顺带升级下,并非必须。注意顺序,先SSL再SSH。
1
2
3
4
5
6
7
8
9
| #cd /usr/local/src
#wget http://www.openssl.org/source/openssl-0.9.8e.tar.gz
#wget ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-4.6p1.tar.gz
#tar xzvf openssl-0.9.8e.tar.gz
#cd openssl-0.9.8e
#./config --prefix=/usr/local/openssl
#make
#make test
#make install |
1
2
3
4
5
6
| #cd ..
#tar xzvf openssh-4.6p1.tar.gz
#cd openssh-4.6p1
#./configure --prefix=/usr --with-pam --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/openssl --with-md5-passwords --mandir=/usr/share/man
#make
#make install |
用
查看版本。
-
接下来生成对应服务器的key/crt文件
1
| [root@bbs ~]#openssl genrsa -des3 -out server.key 1024 |
这里会提示你输入一个密码。
根据Key生成一个CSR
1
| [root@bbs ~]#openssl req -new -key server.key -out server.csr |
自己给自己颁发一个证书
1
| [root@bbs ~]# openssl req -new -x509 -nodes -sha1 -days 365 -key server.key -out server.crt |
ok,保存好.crt和.key文件。.csr文件不需要了。
Apache使用的是.crt+.key文件。而nginx使用的是.pem+.key文件。
.pem文件很简单,直接把.crt和.key复制出来,粘贴到新的.pem文件里就行了。
Apache的配置。虚拟主机部分增加:
1
2
3
4
5
6
7
8
9
10
11
12
| <VirtualHost bbs.nau.edu.cn:443>
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /data/certfile/server.crt
SSLCertificateKeyFile /data/certfile/server.key
BrowserMatch ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
ServerAdmin baalchina@nau.edu.cn
DocumentRoot /data/web/bbs
ServerName bbs.nau.edu.cn:443
</VirtualHost> |
如果是nginx,那么:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| server {
listen 443;
server_name bbs.nau.edu.cn;
if ($uri !~* "/logging.php$") {
rewrite ^/(.*)$ http://$host/$1 redirect;
}
ssl on;
ssl_certificate /data/certfile/server.pem;
ssl_certificate_key /data/certfile/server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
} |
其他部分和http server是一样的。
在https server下加入如下配置:
if ($uri !~* "/logging.php$")
{
rewrite ^/(.*)$ http://$host/$1 redirect;
} |
在http server下加入如下配置:
if ($uri ~* "/logging.php$")
{
rewrite ^/(.*)$ https://$host/$1 redirect;
} |
最后结果就是,用户会且只会在访问logging.php的情况下,才会通过https访问。有效地避免了arp欺骗、嗅探等方法盗取账号密码的行为。
感谢nginx作者的帮助。
http://marc.info/?l=nginx&m=121663148102512&w=2