码迷,mamicode.com
首页 > Web开发 > 详细

LNMP中APACHE配置虚拟主机和个人主页

时间:2015-06-07 21:50:31      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:虚拟主机   apache   个人主页   

关掉主配置文件中的网页设置

#DocumentRoot "/usr/local/apache2//htdocs"

#<Directory "/usr/local/apache2//htdocs">

#    Options Indexes FollowSymLinks

#    AllowOverride None

#    <RequireAll>

#    Require all granted

#    Require not ip 192.168.193.1

#    </RequireAll>

#</Directory>

 开启虚拟主机选项

 Include etc//extra/httpd-vhosts.conf

 

基于IP的虚拟主机:

一台服务器,多个IP,搭建多个网站

vim etc/extra/httpd-vhosts.conf

<VirtualHost 192.168.193.2>

#    ServerAdmin webmaster@dummy-host.example.com

    DocumentRoot "/usr/local/apache2/htdocs/baidu"

    ServerName www.baidu.com

#    ServerAlias www.dummy-host.example.com

    ErrorLog "logs/dummy-host.example.com-error_log"

    CustomLog "logs/dummy-host.example.com-access_log" common

    <Directory "/usr/local/apache2/htdocs/baidu">

        require all granted

    </Directory>

</VirtualHost>

 

<VirtualHost 192.168.193.4>

#    ServerAdmin webmaster@dummy-host2.example.com

    DocumentRoot "/usr/local/apache2/htdocs/xdl"

    ServerName www.xdl.com

    ErrorLog "logs/dummy-host2.example.com-error_log"

    CustomLog "logs/dummy-host2.example.com-access_log" common

    <Directory "/usr/local/apache2/htdocs/xdl">

        require all granted

    </Directory>

</VirtualHost>

 

基于端口的虚拟主机

一台服务器,一个ip,搭建多个网站,每个网络使用不同端口访问

vim etc/extra/httpd-vhosts.conf

#Listen 80

Listen 8080

<VirtualHost 192.168.193.2:80>

#    ServerAdmin webmaster@dummy-host.example.com

    DocumentRoot "/usr/local/apache2/htdocs/baidu"

    ServerName www.baidu.com

"etc/extra/httpd-vhosts.conf" 53L, 1717C                  23,1         顶端

    DocumentRoot "/usr/local/apache2/htdocs/baidu"

    ServerName www.baidu.com

#    ServerAlias www.dummy-host.example.com

    ErrorLog "logs/dummy-host.example.com-error_log"

    CustomLog "logs/dummy-host.example.com-access_log" common

    <Directory "/usr/local/apache2/htdocs/baidu">

        require all granted

        options Indexes

        Allowoverride None

    </Directory>

</VirtualHost>

 

<VirtualHost 192.168.193.2:8080>

#    ServerAdmin webmaster@dummy-host2.example.com

    DocumentRoot "/usr/local/apache2/htdocs/xdl"

    ServerName www.xdl.com

    ErrorLog "logs/dummy-host2.example.com-error_log"

    CustomLog "logs/dummy-host2.example.com-access_log" common

    <Directory "/usr/local/apache2/htdocs/xdl">

        require all granted

        options Indexes

        Allowoverride None

    </Directory>

</VirtualHost>

 

基于域名的虚拟主机

一台服务器,一个ip,搭建多个网站,每个网站使用不同域名访问

<VirtualHost *:80>

#    ServerAdmin webmaster@dummy-host.example.com

    DocumentRoot "/usr/local/apache2/htdocs/baidu"

    ServerName www.baidu.com

<sr/local/apache2/etc/extra/httpd-vhosts.conf" 53L, 1690C 25,1         顶端

    DocumentRoot "/usr/local/apache2/htdocs/baidu"

    ServerName www.baidu.com

#    ServerAlias www.dummy-host.example.com

    ErrorLog "logs/dummy-host.example.com-error_log"

    CustomLog "logs/dummy-host.example.com-access_log" common

    <Directory "/usr/local/apache2/htdocs/baidu">

        require all granted

        options Indexes

        Allowoverride None

    </Directory>

</VirtualHost>

 

<VirtualHost *:80>

#    ServerAdmin webmaster@dummy-host2.example.com

    DocumentRoot "/usr/local/apache2/htdocs/xdl"

    ServerName www.qq.com

    ErrorLog "logs/dummy-host2.example.com-error_log"

    CustomLog "logs/dummy-host2.example.com-access_log" common

    <Directory "/usr/local/apache2/htdocs/xdl">

        require all granted

        options Indexes

        Allowoverride None

    </Directory>

</VirtualHost>

 

将域名www.baidu.comwww.qq.comDNS服务器中解析

 

为每个用户分别添加不同的个人主页:

启用主配置文件的访问设置

LoadModule userdir_module modules/mod_userdir.so

Include etc//extra/httpd-userdir.conf

 

#vim /usr/local/apache2/etc/extra/httpd-userdir.con

UserDir public_html

 

#

# Control access to UserDir directories.  The following is an example

# for a site where these directories are restricted to read-only.

#

<Directory "/home/*/public_html">

    AllowOverride FileInfo AuthConfig Limit Indexes

    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

    Require method GET POST OPTIONS

</Directory>

 

默认设置就可以不用修改

用户家目录中建立 public_html 文件,并修改用户家目录的权限有读权限

drwx-----x. 4 lf          lf           4096 5月  29 19:46 lf

drwx-----x. 4 fengyunfan  fengyunfan   4096 5月  29 19:48 fengyunfan


本文出自 “风云帆” 博客,请务必保留此出处http://fengyunfan.blog.51cto.com/6663935/1659409

LNMP中APACHE配置虚拟主机和个人主页

标签:虚拟主机   apache   个人主页   

原文地址:http://fengyunfan.blog.51cto.com/6663935/1659409

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!