![]() |
|
|
| 付款方式 在线问答 |
|
在lighttpd上配置基于mysql的虚拟主机lighttpd是一款轻量级的web服务,默认支持虚拟主机,但是我们希望通过增加一些简单的代码获得虚拟主机对mysql的支持。 # mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.0.51a-3ubuntu5.2 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> grant all on lighttpd.* to lighttpd@localhost identified by 'abc123'; Query OK, 0 rows affected (0.07 sec) mysql> exit Bye # mysql -ulighttpd -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 5.0.51a-3ubuntu5.2 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create database lighttpd; Query OK, 1 row affected (0.08 sec) mysql> use lighttpd Database changed mysql> mysql> create table domains( -> domain varchar(100) not null primary key, -> docroot varchar(200) not null, -> config text); Query OK, 0 rows affected (0.04 sec)
mysql> insert into domains values( -> 'www.foo.com','/var/www/www.foo.com/','dir-listing.activate="enable"\nalias.url=("/"=>"/var/www/www.foo.com/")'); Query OK, 1 row affected (0.09 sec) mysql> insert into domains values('www.bar.com','/var/www/www.bar.com/','dir-listing.activate="disable"'); Query OK, 1 row affected (0.01 sec)
# cat /usr/share/lighttpd/mysql_vhost.py #!/usr/bin/env python import sys import MySQLdb # load configuration data from the database db=MySQLdb.connect(host='localhost', db=sys.argv[1], user=sys.argv[2], \ passwd=sys.argv[3]) cur = db.cursor() cur.execute("SELECT * FROM domains") rs=cur.fetchall() db.close() for domain in rs: print "$HTTP[\"host\"] == \"%s\" {\nserver.document-root = \"%s\"\n%s\n}" % \ (domain[0], domain[1], domain[2])
include_shell "/usr/share/lighttpd/mysql_vhost.py lighttpd lighttpd abc123"
ln -sf ../conf-available/10-vhost.conf .
|
|
上海电信漕宝机房 地址:漕宝路1600号 漕宝机房介绍 上海移动双线机房 机房地址: 金沙江路1340弄 双线机房介绍
公司地址:上海市普陀区清峪路368弄12号301 邮编:200333 电话 021-52691612 传真 021-52693626 《增值电信业务经营许可证》许可证编号: 沪ICP备05001352号 上海市互联网违法与违规信息举报中心 上海市互联网协会 上海市电子商务行业协会 DNS Stuff 公益性SEO 页面执行时间:46.875毫秒 上海纵智信息技术有限公司 版权所有 2004-2007 营业执照 |