首页 > 代码库 > 使用apache进行域名绑定

使用apache进行域名绑定

【背景】

  项目需要搭建一套mysqlapi的开发环境,进行域名绑定

【方法】

主要方式通过修改apache的vhost配置文件,重启apache服务,以及最终在客户端绑定hosts。

 

1、查看apache服务目录

[root@alice48 10.73.13.48 sinasrv2]# ps aux |grep httpdroot      1488  0.0  0.1 336416 13904 ?        Ss   Jul03   0:00 /usr/local/sinasrv2/sbin/httpd -k restartwww       8449  0.0  0.1 339244 13212 ?        S    04:02   0:00 /usr/local/sinasrv2/sbin/httpd -k restartwww       8450  0.0  0.1 340780 14496 ?        S    04:02   0:02 /usr/local/sinasrv2/sbin/httpd -k restartwww       8451  0.0  0.1 340080 13784 ?        S    04:02   0:00 /usr/local/sinasrv2/sbin/httpd -k restartwww       8452  0.0  0.0 336932 11456 ?        S    04:02   0:00 /usr/local/sinasrv2/sbin/httpd -k restartwww       8453  0.0  0.1 340784 14720 ?        S    04:02   0:03 /usr/local/sinasrv2/sbin/httpd -k restartwww      16928  0.0  0.1 340780 14188 ?        S    06:50   0:00 /usr/local/sinasrv2/sbin/httpd -k restartroot     18487  0.0  0.0  61164   764 pts/27   S+   10:37   0:00 grep httpdwww      28401  0.0  0.0 339024 11964 ?        S    09:47   0:00 /usr/local/sinasrv2/sbin/httpd -k restart

目录所在的地方为/usr/local/sinasrv2,该目录下的文件为

[root@alice48 10.73.13.48 sinasrv2]# cd /usr/local/sinasrv2[root@alice48 10.73.13.48 sinasrv2]# lltotal 60drwxr-xr-x  3 root   root  4096 May  6 16:11 bindrwxr-xr-x  2 root   root  4096 Aug  8  2011 distcachedrwxr-xr-x  8 www    www  12288 Jul  9 10:32 etcdrwxr-xr-x 13 root   root 12288 Mar 10 09:49 includedrwxr-xr-x 15 root   root  4096 Jun  7 21:29 liblrwxrwxrwx  1 root   root    23 Jan 13  2011 lib64 -> /usr/local/sinasrv2/liblrwxrwxrwx  1 root   root    17 Jan 13  2011 modules -> lib/httpd/modulesdrwxr-xr-x  3 root   root  4096 Dec 19  2012 romedrwxr-xr-x  2 root   root  4096 Dec  3  2013 sbindrwx------  2 nobody root  4096 Mar 18  2011 scgi_tempdrwxr-xr-x 14 root   root  4096 Nov 27  2012 sharedrwx------  2 nobody root  4096 Mar 18  2011 uwsgi_tempdrwxr-xr-x  5 root   root  4096 Jul  2  2013 var

  

2、修改apache的vhost配置文件

 vim /usr/local/sinasrv2/etc/httpd.conf

添加如下内容:

<VirtualHost *:80>    ServerAdmin xinyu7@staff.sina.com.cn    DocumentRoot /data1/www/htdocs/dpadmint-dev.grid.sina.com.cn    ServerName api-dev.mysql.cluster.sina.com.cn    ErrorLog /data1/www/logs/api-dev.mysql.cluster.sina.com.cn-error_log    CustomLog /data1/www/logs/api-dev.mysql.cluster.sina.com.cn-access_log combined    ProxyPass / http://127.0.0.1:6184/    ProxyPreserveHost on</VirtualHost>

  

  

3、重启apache服务

[root@alice48 10.73.13.48 etc]# apachectl restart[root@alice48 10.73.13.48 etc]# ps aux |grep httpdroot      1488  0.0  0.1 336416 13924 ?        Ss   Jul03   0:00 /usr/local/sinasrv2/sbin/httpd -k restartwww      23323  0.0  0.0 336416  6992 ?        S    10:48   0:00 /usr/local/sinasrv2/sbin/httpd -k restartwww      23324  0.0  0.0 336416  6992 ?        S    10:48   0:00 /usr/local/sinasrv2/sbin/httpd -k restartwww      23325  0.0  0.0 336416  6992 ?        S    10:48   0:00 /usr/local/sinasrv2/sbin/httpd -k restartwww      23326  0.0  0.0 336416  6992 ?        S    10:48   0:00 /usr/local/sinasrv2/sbin/httpd -k restartwww      23327  0.0  0.0 336416  6992 ?        S    10:48   0:00 /usr/local/sinasrv2/sbin/httpd -k restartroot     23329  0.0  0.0  61164   764 pts/27   S+   10:48   0:00 grep httpd

  

4、 测试校验

绑定host

http://api-dev.mysql.cluster.sina.com.cn/autogrant/get_grant_db?token=2c9c17acee&username=guosong&port=6011

输出结果为

{"status": 0, "result": {"database": ["elink"]}, "request_id": 1208541870}