Ubuntu Apache绑定多域名
1,Ubuntu 版本
ubuntu@ip-172-31-18-250:~$ cat /etc/issue Ubuntu 14.04 LTS \n \l
2,Apache版本
ubuntu@ip-172-31-18-250:~$ apache2 -v Server version: Apache/2.4.7 (Ubuntu) Server built: Apr 3 2014 12:20:28ubuntu@ip-172-31-18-250:~$ cd /etc/apache2 ubuntu@ip-172-31-18-250:/etc/apache2$ ls -l total 80 -rw-r--r-- 1 root root 7115 Jan 7 21:23 apache2.conf drwxr-xr-x 2 root root 4096 Jun 10 14:58 conf-available drwxr-xr-x 2 root root 4096 Jun 10 14:58 conf-enabled -rw-r--r-- 1 root root 1782 Jan 3 22:48 envvars -rw-r--r-- 1 root root 31063 Jan 3 22:48 magic drwxr-xr-x 2 root root 12288 Jun 10 15:53 mods-available drwxr-xr-x 2 root root 4096 Jun 10 15:53 mods-enabled -rw-r--r-- 1 root root 320 Jan 7 21:23 ports.conf drwxr-xr-x 2 root root 4096 Jun 13 15:45 sites-available drwxr-xr-x 2 root root 4096 Jun 13 15:49 sites-enabled
4,文件夹sites-enabled和 sites-available下面是与绑定域名有关的文件,
ubuntu@ip-172-31-18-250:/etc/apache2/sites-available$ ls -l total 20 -rw-r--r-- 1 root root 1332 Jan 7 21:23 000-default.conf -rw-r--r-- 1 root root 6437 Jan 7 21:23 default-ssl.conf -rw-r--r-- 1 root root 1367 Jun 13 15:45 luckybird.me.conf -rw-r--r-- 1 root root 1371 Jun 10 16:29 www.luckybird.me.conf ubuntu@ip-172-31-18-250:/etc/apache2/sites-enabled$ ls -l total 0 lrwxrwxrwx 1 root root 35 Jun 10 16:38 000-default.conf -> ../sites-available/000-default.conf lrwxrwxrwx 1 root root 36 Jun 13 15:49 luckybird.me.conf -> ../sites-available/luckybird.me.conf lrwxrwxrwx 1 root root 40 Jun 10 16:36 www.luckybird.me.conf -> ../sites-available/www.luckybird.me.conf
5,绑定多个域名对应多个文件,以www.luckybird.me.conf为例
ubuntu@ip-172-31-18-250:/etc/apache2/sites-enabled$ vim www.luckybird.me.conf # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost ServerName www.luckybird.me DocumentRoot /var/www/html/luckybird # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
关键添加一下两行
ServerName www.luckybird.me DocumentRoot /var/www/html/luckybird
6,在sites-available建立对应域名的文件,然后链接到sites-enabled下面
ubuntu@ip-172-31-18-250:/etc/apache2/sites-enabled$ ln -s ../sites-available/www.luckybird.me.conf www.luckybird.me.conf
7,重启Apache即可生效
Leave a Reply