unbuntu apahce 2 设置 多域名

1.找到apache2 的设置路径

默认的apache的路径为/etc/apache2/

 

2. 修改httpd.conf

本文192.168.0.1 为自己的服务器的ip,下面一样的意思

ServerName 192,168.0.1:80
NameVirtualHost 192,168.0.1.166

 

3. 修改 /etc/apache2/sites-available/default文件 此文件为第一个网站的域名绑定信息

<VirtualHost 192.168.0.1>
    Servername qq.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        #AllowOverride None
        AllowOverride ALL 
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        #AllowOverride None
        AllowOverride ALL 
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

 

4. 增加新的域名的配置信息/etc/apache2/sites-available/test

<VirtualHost 192.168.0.1>
    Servername appask.cn
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/testaaaaa
	<Directory />
		Options FollowSymLinks
		#AllowOverride None
		AllowOverride ALL 
	</Directory>
	<Directory /var/www/app>
		Options Indexes FollowSymLinks MultiViews
		#AllowOverride None
		AllowOverride ALL 
		Order allow,deny
		allow from all
	</Directory>
	
	ErrorLog ${APACHE_LOG_DIR}/error_app.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog ${APACHE_LOG_DIR}/access_app.log combined

</VirtualHost>

  

5. 执行 sudo a2ensite test 在sites-enable可以看到多了一个指向test的软链接

 

6.重启apache2 : service apache2 restart

 

一切就Ok了

 

你可能感兴趣的