澳门新萄京官方网站-www.8455.com-澳门新萄京赌场网址

只可以访谈到主页怎么做,apache服务试验笔记

2019-12-12 作者:www.8455.com   |   浏览(198)

Linux配置虚拟主机后,只能访问到主页怎么办?

Apache服务器

1、基于ip地址的虚拟主机

如何实现apache虚拟主机配置。

今天配置了lamp后,添加了一个虚拟主机,配置http.conf后,增加虚拟主机,测试访问发现只有域名下能访问,ljt.com但是域名下所有的都访问不到。

一 简介

复制代码 代码如下:

1、基于ip地址的虚拟主机
Listen 80
<VirtualHost 172.20.30.40>
DocumentRoot /home/httpd/html1
ServerName www.ok1.com
ErrorLog /usr/local/apache/logs/error1_log
CustomLog /usr/local/apache/logs/access1_log combined
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot /home/httpd/html2
ServerName www.ok2.com
ErrorLog /usr/local/apache/logs/error2_log
CustomLog /usr/local/apache/logs/access2_log combined
</VirtualHost>
2、基于IP 和多端口的虚拟主机配置
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080

Httpd-vhost..conf

1 www:world  wide  web 万维网

Listen 80
<VirtualHost 172.20.30.40>
    DocumentRoot /home/httpd/html1
    ServerName www.ok1.com
    ErrorLog /usr/local/apache/logs/error1_log
    CustomLog /usr/local/apache/logs/access1_log combined
</VirtualHost>
<VirtualHost 172.20.30.50>
    DocumentRoot /home/httpd/html2
    ServerName www.ok2.com
    ErrorLog /usr/local/apache/logs/error2_log
    CustomLog /usr/local/apache/logs/access2_log combined
</VirtualHost>

<VirtualHost 172.20.30.40:80>
DocumentRoot /www/example1-80
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
DocumentRoot /www/example1-8080
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName www.example1.org
</VirtualHost>
<VirtualHost 172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName www.example2.org
</VirtualHost>
3、单个IP 地址的服务器上基于域名的虚拟主机配置
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here
</VirtualHost>
如果您感觉上面的文章还不够详细可以看下下面的文章:

<VirtualHost *:80>

http 协议: 超文本传输协议

 2、基于IP 和多端口的虚拟主机配置

实验目标:在apache实现基于域名的虚拟主机
实验用的XAMPP版本为1.7.7,内含apache版本为2.2.21

DocumentRoot "/usr/local/apache/htdocs/cyds"

HTML语言: 超文本标识语言

复制代码 代码如下:

实验前准备:
1.

ServerName cyds.ljt.com

2 URL:统一资源定位 协议 域名:端口 网页文件名

Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080

为了测试不同的域名,在Windows/System32/drivers/etc/下觅得hosts文件,在其中添加实验用的域名若干,如

127.0.0.1 test1.net
127.0.0.1 test2.net
如此,则在浏览器中输入该俩域名时,Windows将其解析为127.0.0.1本地地址。即,在浏览器中访问localhost, test1.net, test2.net均可访问XAMPP的欢迎页。
2. 在apache目录下建立目录,以放置您不同的网站。为保护XAMPP原有的htdocs中的欢迎页内容,实验另外建立了与htdocs平级的htdocs1目录,在其下建立了test1.net, test2.net两个子目录用以放置实验用的网站。如下 -
apache/htdocs1/test1.net - 放置test1.net网站内容
apache/htdocs1/test2.net - 放置test2.net网站内容
在这两个目录中各新建hello world一网页 index.html,内容 -
<HTML>
<HEAD></HEAD>
<BODY>
<H1>hello~, 这是[对应的网站名,用以区别].net</H1></BODY>
</HTML>
实验步骤:

  1. 找到apache/conf/httpd.conf, 将其中的
    ServerAdmin
    ServerName
    DocumentRoot
    注释掉。

  2. 在httpd.conf中,找到行
    Include "conf/extra/httpd-vhosts.conf"
    如被注释则解注。该文件记载了虚拟主机的参数。[以前虚拟主机参数是直接填写在httpd.conf中的,为了更好地组织文件,将其分离出去,类似于某些编程语言一样。因此httpd.conf中include它,即相当于把它的内容填在了httpd.conf中。]

  3. 这个httpd-vhosts.conf文件格式基本如下 -
    #blah-blah
    NameVirtualHost *:80
    #blah-blah
    #blah-blah
    <VirtualHost *:80>
    ServerAdmin XXXXXXXX
    DocumentRoot "XXXXXXXX"
    ServerName XXXXXXX
    ServerAlias XXXXXX
    ErrorLog "logs/XXXXXX-error.log"
    CustomLog "logs/XXXXXXX-error.log" combined
    </VirtualHost>
    需要修改的,就是<VirtualHost>中的参数了。这个可以参见apache官方文档。根据实验域名,可以增加两个<VirtualHost>:
    <VirtualHost *:80>
    ServerAdmin adm@test1.net
    DocumentRoot "C:/xampp/htdocs1/test1.net"
    ServerName test1.net
    ServerAlias www.test1.net
    ErrorLog "logs/test1-error.log"
    CustomLog "logs/test1-access.log" combined

<Directory "C:/xampp/htdocs1/test1.net">
order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin adm@test2.net
DocumentRoot "C:/xampp/htdocs1/test2.net"
ServerName test2.net
ServerAlias www.test2.net
ErrorLog "logs/test1-error.log"
CustomLog "logs/test1-access.log" combined

<Directory "C:/xampp/htdocs1/test2.net">
order allow,deny
allow from all
</Directory>
</VirtualHost>
注意,如果不在各VirtualHost中定义Directory的可访问性,你将遇到的是Access Forbidden!就连原来的localhost也是。

  1. 由于之前注释掉了httpd.conf中的ServerName, DocumentRoot等,为了仍然能以localhost访问原XAMPP欢迎页,就在增加一个VirtualHost,如下
  • <VirtualHost *:80>
    ServerAdmin adm@localhost
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost

ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" combined

<Directory "C:/xampp/htdocs">
order allow,deny
allow from all
</Directory>
</VirtualHost>
为了避免出错,把它放置在第一个Virtualhost位置。

至此,apache基于域名的虚拟主机配置完成。可以通过
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:;
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin kongdaoxian@gmail.com
DocumentRoot "E:/jbxue/apache2/htdocs"
ServerName localhost
ServerAlias www.jbxue.com
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" combined

<Directory "E:/jbxue/apache2/htdocs">
order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin kongdaoxian@gmail.com
DocumentRoot "E:/jbxue/apache2/htdocs/project1"
ServerName project1.com
ServerAlias www.project1.com
ErrorLog "logs/project1-error.log"
CustomLog "logs/project1-access.log" combined

<Directory "E:/jbxue/apache2/htdocs/project1">
order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin kongdaoxian@gmail.com
DocumentRoot "E:/jbxue/apache2/htdocs/jbxue/public"
ServerName jbxue.com
ServerAlias www.jbxue.com
DirectoryIndex index.php
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin kongdaoxian@gmail.com
DocumentRoot "E:/jbxue/apache2/htdocs/jbxue"
ServerName jbxue.com
ServerAlias www.jbxue.com
# DirectoryIndex index.php
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin kongdaoxian@gmail.com
DocumentRoot "E:/jbxue/apache2/htdocs/test"
ServerName test.com
ServerAlias www.test.com
ErrorLog "logs/jbxue-error.log"
CustomLog "logs/jbxue-access.log" combined

<Directory "E:/jbxue/apache2/htdocs/test">
order allow,deny
allow from all
</Directory>
</VirtualHost>

Errorlog logs/cyds.ljt.com.err

                 

<VirtualHost 172.20.30.40:80>
 DocumentRoot /www/example1-80
 ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.40:8080>

CustomLog logs/cyds.ljt.com.access common

3 搭建www的服务器的方法

 DocumentRoot /www/example1-8080
 ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.50:80>
 DocumentRoot /www/example2-80
 ServerName www.example1.org
</VirtualHost>
<VirtualHost 172.20.30.50:8080>
 DocumentRoot /www/example2-8080
 ServerName www.example2.org
</VirtualHost>

<Directory "/usr/local/apache/htdocs/cyds">

windows   IIS asp SQLserver

3、单个IP 地址的服务器上基于域名的虚拟主机配置

Options FollowSymLinks

Internet  Information  server

复制代码 代码如下:

AllowOverride None

Linux apache mysql php

# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here
</VirtualHost>

Order allow,deny

二 安装

如果您感觉上面的文章还不够详细可以看下下面的文章:

Allow from all

1、lamp源码安装

实验目标:在apache实现基于域名的虚拟主机
实验用的XAMPP版本为1.7.7,内含apache版本为2.2.21

</Directory>

                       生产环境    安全  稳定   错误提示关闭    源码包,技术要求高,复杂

实验前准备:

</VirtualHost>

 

1.

查了半天资料:

实验环境(复制的生产环境 错误提示开启)

为了测试不同的域名,在Windows/System32/drivers/etc/下觅得hosts文件,在其中添加实验用的域名若干,如

复制代码 代码如下:

127.0.0.1   test1.net
127.0.0.1   test2.net

如此,则在浏览器中输入该俩域名时,Windows将其解析为127.0.0.1本地地址。即,在浏览器中访问localhost, test1.net, test2.net均可访问XAMPP的欢迎页。

2. 在apache目录下建立目录,以放置您不同的网站。为保护XAMPP原有的htdocs中的欢迎页内容,实验另外建立了与htdocs平级的htdocs1目录,在其下建立了test1.net, test2.net两个子目录用以放置实验用的网站。如下 -
apache/htdocs1/test1.net - 放置test1.net网站内容
apache/htdocs1/test2.net - 放置test2.net网站内容

 在这两个目录中各新建hello world一网页 index.html,内容 -

复制代码 代码如下:

<HTML>
<HEAD></HEAD>
<BODY>
<H1>hello~, 这是[对应的网站名,用以区别].net</H1></BODY>
</HTML> 

实验步骤:

  1. 找到apache/conf/httpd.conf, 将其中的

ServerAdmin
ServerName
DocumentRoot
注释掉。

  1. 在httpd.conf中,找到行

 Include "conf/extra/httpd-vhosts.conf"
如被注释则解注。该文件记载了虚拟主机的参数。[以前虚拟主机参数是直接填写在httpd.conf中的,为了更好地组织文件,将其分离出去,类似于某些编程语言一样。因此httpd.conf中include它,即相当于把它的内容填在了httpd.conf中。]

  1. 这个httpd-vhosts.conf文件格式基本如下 -

复制代码 代码如下:

#blah-blah
NameVirtualHost *:80
#blah-blah
#blah-blah
<VirtualHost *:80>
    ServerAdmin XXXXXXXX
    DocumentRoot "XXXXXXXX"
    ServerName XXXXXXX
    ServerAlias XXXXXX
    ErrorLog "logs/XXXXXX-error.log"
    CustomLog "logs/XXXXXXX-error.log" combined  
</VirtualHost>

需要修改的,就是<VirtualHost>中的参数了。这个可以参见apache官方文档。根据实验域名,可以增加两个<VirtualHost>:

复制代码 代码如下:

<VirtualHost *:80>
    ServerAdmin adm@test1.net
    DocumentRoot "C:/xampp/htdocs1/test1.net"
    ServerName test1.net
    ServerAlias www.test1.net
    ErrorLog "logs/test1-error.log"
    CustomLog "logs/test1-access.log" combined

    <Directory "C:/xampp/htdocs1/test1.net">
    order allow,deny
    allow from all
    </Directory>   
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin adm@test2.net
    DocumentRoot "C:/xampp/htdocs1/test2.net"
    ServerName test2.net
    ServerAlias www.test2.net
    ErrorLog "logs/test1-error.log"
    CustomLog "logs/test1-access.log" combined

    <Directory "C:/xampp/htdocs1/test2.net">
    order allow,deny
    allow from all
    </Directory>   
</VirtualHost>

注意,如果不在各VirtualHost中定义Directory的可访问性,你将遇到的是Access Forbidden!就连原来的localhost也是。

  1. 由于之前注释掉了httpd.conf中的ServerName,

    DocumentRoot等,为了仍然能以localhost访问原XAMPP欢迎页,就在增加一个VirtualHost,如下

复制代码 代码如下:

<VirtualHost *:80>
    ServerAdmin adm@localhost
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost

    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" combined

    <Directory "C:/xampp/htdocs">
    order allow,deny
    allow from all
    </Directory>   
</VirtualHost>

为了避免出错,把它放置在第一个Virtualhost位置。

至此,apache基于域名的虚拟主机配置完成。可以通过

#
# Virtual Hosts
#

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:;
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

<VirtualHost *:80>
    ServerAdmin kongdaoxian@gmail.com
    DocumentRoot "E:/skydao/apache2/htdocs"
    ServerName localhost
    ServerAlias www.skydao.com
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" combined

    <Directory "E:/skydao/apache2/htdocs">
    order allow,deny
    allow from all
    </Directory>   
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin kongdaoxian@gmail.com
    DocumentRoot "E:/skydao/apache2/htdocs/project1"
    ServerName project1.com
    ServerAlias www.project1.com
    ErrorLog "logs/project1-error.log"
    CustomLog "logs/project1-access.log" combined

    <Directory "E:/skydao/apache2/htdocs/project1">
    order allow,deny
    allow from all
    </Directory>   
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin kongdaoxian@gmail.com
    DocumentRoot "E:/skydao/apache2/htdocs/zendTest/public"
    ServerName zendTest.com
    ServerAlias www.zendTest.com
    DirectoryIndex index.php
    <Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
    </Directory>   
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin kongdaoxian@gmail.com
    DocumentRoot "E:/skydao/apache2/htdocs/testRewrite"
    ServerName testRewrite.com
    ServerAlias www.testRewrite.com
    # DirectoryIndex index.php
    <Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
    </Directory>   
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin kongdaoxian@gmail.com
    DocumentRoot "E:/skydao/apache2/htdocs/test"
    ServerName test.com
    ServerAlias www.test.com
    ErrorLog "logs/zendTest-error.log"
    CustomLog "logs/zendTest-access.log" combined

    <Directory "E:/skydao/apache2/htdocs/test">
    order allow,deny
    allow from all
    </Directory>   
</VirtualHost>

少了权限问题:

 

您可能感兴趣的文章:

  • Apache 虚拟目录和默认首页的设置
  • apache中伪静态配置和使用(Apache虚拟主机下Discuz伪静态)
  • 本地机apache配置基于域名的虚拟主机详解
  • Apache 添加虚拟目录注意事项
  • windows apache多端口虚拟主机配置方法
  • apache虚拟主机中设置泛域名解析的方法
  • apache虚拟机配置步骤和修改访问端口的方法(虚拟机端口映射)
  • Apache 配置多端口 多虚拟主机 局域网访问示例
  • Apache 多站点虚拟主机配置方法
  • win10 apache配置虚拟主机后localhost无法使用的解决方法

最后我们需要在apache配置文件/opt/lampp/etc/httpd.conf中添加一下网站目录的访问权限。

开发环境 源码包 二进制包

<Directory "/opt/lampp/www/site1">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

 

 

2、rpm包安装     yum安装

 

httpd

配置lamp环境虚拟主机参考:

mysql

mysql-server

php

php-devel

php-mysql

三 相关文件

apache配置文件

源码包安装:/usr/lcoal/apache2/etc/httpd.conf

    /usr/local/apache2/etc/extra/*.conf 

rpm包安装:/etc/httpd/conf/httpd.conf

默认网页保存位置: 

网站根目录:/usr/local/apache2/htdocs/

rpm包安装:/var/www/html/

日志保存位置

网站日志:/usr/local/apache2/logs/

rpm包: /var/log/httpd/

            rpm包默认使用日志处理程序   /var下都会轮替   源码包才需要设置

日志处理:

#tail -f  access_log   动态查看文件 

1日志切割  apache自带日志里面自带日志切割

2日志轮替  linux自带日志管理logrotate.conf加入

#vim /etc/logrotate.conf

/usr/local/apache2/logs/access_log{

                                 daily

                                 rotate  30

}

       

#logrotate -f /etc/logrotate.conf 手动运行
#cd /usr/local/apache2/logs/
#ls

             所有日志都要进行日志轮替

四 配置文件

vi /root/.bashrc

   alias sta=’/usr/local/apache2/bin/apachectl start’

   alias sto=’/usr/local/apache2/bin/apachectl stop’

source /root/.bashrc

#sto
#sta

注意:apache配置文件严格区分大小写

1 针对主机环境的基本配置

ServerRoot apache主目录          

Listen 监听端口              

LoadModule 加载的相关模块

User

Group 用户和组

ServerAdmin 管理员邮箱

ServerName 服务器名(没有域名解析时,使用临时解析。不开启)

ErrorLog "logs/error_log 错误日志

CustomLog "logs/access_log" common 正确访问日志

DirectoryIndex index.html index.php 默认网页文件名,优先级顺序

Include  etc/extra/httpd-vhosts.conf 子配置文件中内容也会加载生效

2 主页目录及权限  

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

主页目录

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

#Directory关键字定义目录权限

Options Indexes FollowSymLinks                    

#options

None:没有任何额外权限

All: 所有权限

Indexes:浏览权限(当此目录下没有默认网页文件时,显示目录内容)

FollowSymLinks:准许软连接到其他目录

AllowOverride None

#定义是否允许目录下.htaccess文件中的权限生效

None:.htaccess中权限不生效

All:文件中所有权限都生效

AuthConfig:文件中,只有网页认证的权限生效。

Require all granted 访问控制列表   403错误   404错误

#定义此目录的允许访问权限

例1:仅允许IP为192.168.1.1的主机访问

      Require all  denied

      Require ip 192.168.1.1

例子2.仅允许192.168.1.0/24网络的主机访问

      Require  all  denied

      Require ip 192.168.1.0/24

例子3.禁止192.168.1.2的主机访问,其他的都允许访问,

<RequireAll>

      Require all  granted

      Require not ip 192.168.1.2                        

</RequireAll>

例子4.允许所有访问,

Require all  granted

例子5.拒绝所有访问,

Require all  denied

3 目录别名  用途 扩展网站目录,增加服务器,使用二级域名,使用目录别名    

子配置文件名 etc/extra/httpd-autoindex.conf

Alias /icons/ "/usr/local/apache2//icons/"

    apache以为在这里 实际目录位置

定义别名  /icons/----               

<Directory "/usr/local/apache2//icons">

    Options Indexes MultiViews

    AllowOverride None

    Require all granted                   

</Directory>

修改子配置文件
#vim /usr/local/apache2/extra/httpd-autoindex.conf
29 Alias /www/ "/usr/local/apache2/www/"
30 <Directory "/usr/local/apache2/www/">
31 Options Indexes
32 AllowOverride None
33 Require all granted
34 </Directory>

3)建立/usr/local/apache2/www目录
#mkdir /usr/local/apache2/www

4)重启服务 测试
#sto
#sta

测试 192.168.172.251/www/

4 用户认证   

限制特定目录,只有指定用户可以访问。

1) 建立需要保护的目录

使用别名,在系统位置建立目录,然后保护

mkdir  -p  /share/soft

2)修改配置文件,允许权限文件生效

vi  /usr/local/apache2/etc/httpd.conf

453 Include etc//extra/httpd-autoindex.conf

#vim /usr/local/apache2/etc/extra/httpd-autoindex.conf
37 Alias /soft/ "/share/soft/"
38 <Directory "/share/soft/">
39 Options Indexes
40 AllowOverride All
41 Require all granted
42 </Directory>

Alias /soft/ "/share/soft/"

<Directory "/share/soft">

    Options Indexes

    AllowOverride All #开启权限认证文件.htaccess

    Require all granted 

</Directory>

重启apache

3)在指定目录建立权限文件

建立/share/soft/.htaccess权限文件
#vim /share/soft/.htaccess
1 AuthName "172PHP"
2 AuthType basic
3 AuthUserFile /share/apache.passwd
4 require valid-user

cd  /share/soft

vi  .htaccess #不区分大小写

AuthName "50 docs"

#提示信息

AuthType basic

#加密类型

AuthUserFile /share/apache.passwd

#密码文件,文件名自定义。

require valid-user

#允许密码文件中所有用户访问

4)建立密码文件,加入允许访问的用户。用户和系统用户无关

/usr/local/apache2/bin/htpasswd  -c  /share/apache.passwd  test1

-c  建立密码文件,只有添加第一个用户时,才能-c

/usr/local/apache2/bin/htpasswd  -m  /share/apache.passwd  test2

-m  再添加更多用户时

重启服务 测试
#sto
#sta

测试  192.168.172.251/soft/

5 虚拟主机 

1)分类

      基于IP的虚拟主机: 一台服务器,多个IP,搭建多个网站

   基于端口的虚拟主机: 一台服务器,一个ip,搭建多个网站,每个网络使用不同端口访问

    基于名字的虚拟主机: 一台服务器,一个ip,搭建多个网站,每个网站使用不同域名访问

 

 

只可以访谈到主页怎么做,apache服务试验笔记。2)步骤:

① 解析试验域名

192.168.172.251 www.sina.com
192.168.172.251 www.sohu.com

C:WINDOWSsystem32driversetchosts   windows

/etc/hosts   Linux 

② 规划网站主目录

#mkdir /share/sina/
#mkdir /share/sohu/
#vim /share/sina/index.html
#vim /share/sohu/index.html

/share/sina--------------www.sina.com

/share/sohu ------------ www.sohu.com

 

③  修改配置文件

vi  /usr/local/apache2/etc/httpd.conf

465 Include etc//extra/httpd-vhosts.conf

#打开虚拟主机配置文件

vi /usr/local/apache2/etc/extra/httpd-vhosts.conf

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

    Options Indexes

    AllowOverride None

Require all granted 

</Directory>

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

    Options Indexes

    AllowOverride None

    Require all granted 

</Directory>

 

23 <Directory "/share/sina">
24 Options Indexes
25 AllowOverride None
26 Require all granted
27 </Directory>
28
29 <Directory "/share/sohu">
30 Options Indexes
31 AllowOverride None
32 Require all granted
33 </Directory>

 

 

<VirtualHost 192.168.150.253>

#注意,只能写ip

    ServerAdmin webmaster@sina.com

#管理员邮箱

    DocumentRoot "/usr/local/apache2/htdocs/sina"

#网站主目录

    ServerName www.sina.com

#完整域名

    ErrorLog "logs/sina-error_log"

#错误日志

    CustomLog "logs/sina-access_log" common

#访问日志

</VirtualHost>

 

<VirtualHost 192.168.150.253>

    ServerAdmin webmaster@sohu.com

    DocumentRoot "/usr/local/apache2/htdocs/sohu"

    ServerName www.sohu.com

    ErrorLog "logs/sohu.com-error_log"

    CustomLog "logs/sohu.com-access_log" common

</VirtualHost>

 

35 <VirtualHost 192.168.172.251>
36 ServerAdmin webmaster@sina.com
37 DocumentRoot "/share/sina/"
38 ServerName www.sina.com
39 ErrorLog "logs/sina-error_log"
40 CustomLog "logs/sina-access_log" common
41 </VirtualHost>
只可以访谈到主页怎么做,apache服务试验笔记。 42
43 <VirtualHost 192.168.172.251>
44 ServerAdmin webmaster@sohu.com
45 DocumentRoot "/share/sohu/"
46 ServerName www.sohu.com
47 ErrorLog "logs/sohu-error_log"
48 CustomLog "logs/sohu-access_log" common
49 </VirtualHost>

 

重启服务 测试
#sto
#sta

测试 www.sina.com www.sohu.com

6 rewrite 重写功能   URL

在URL中输入一个地址,会自动跳转为另一个

1)域名跳转 www.sina.com  ------>  www.sohu.com

开启虚拟主机,并正常访问 

# vi /usr/local/apache2/etc/httpd.conf

147LoadModule rewrite_module modules/mod_rewrite.so

#打开重写模块,记得重启apache

修改配置文件,使sina目录的.htaccess文件生效

# vi extra/httpd-vhosts.conf

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

    Options Indexes FollowSymLinks

    AllowOverride All

Require all granted 

</Directory>

#vim /usr/local/apache2/etc/extra/httpd-vhosts.conf
23 <Directory "/share/sina">
24 Options Indexes FollowSymLinks
25 AllowOverride All
26 Require all granted
27 </Directory>

vi  /usr/local/apache2/htdocs/sina/.htaccess

建立/share/sina/.htaccess
#vim /share/sina/.htaccess

RewriteEngine on

#开启rewrite功能

RewriteCond %{HTTP_HOST} www.sina.com

把以www.sina.com 开头的内容赋值给HTTP_HOST变量

RewriteRule  .*   

.*  输入任何地址,都跳转到

 

1 RewriteEngine on
2 RewriteCond %{HTTP_HOST} www.sina.com
3 RewriteRule .*

重启服务 测试
#sto
#sta

测试   www.sina.com  -> www.sohu.com

2)网页文件跳转

vi  /usr/local/apache2/htdocs/sina/.htaccess

RewriteEngine on

RewriteRule index(d ).html index.php?id=$1

# 输入index(数值).html时,跳转到index.php文件,同时把数值当成变量传入index.php

#vim /share/sina/.htaccess
1 RewriteEngine on
2 RewriteRule index(d ).html index.php?id=$1

#cd /share/sina
#vim index.php
<?php
echo "yemian rewrite";
?>

测试 www.sina.com/index5.html

7 常用子配置文件

httpd-autoindex.conf apache系统别名

httpd-default.conf 线程控制 *

httpd-info.conf    状态统计网页

httpd-languages.conf 语言编码 *

httpd-manual.conf apache帮助文档

httpd-mpm.conf     最大连接数 *

httpd-multilang-errordoc.conf 错页面 *

httpd-ssl.conf    ssl安全套接字访问

httpd-userdir.conf 用户主目录配置

httpd-vhosts.conf 虚拟主机

 

本文由澳门新萄京官方网站发布于www.8455.com,转载请注明出处:只可以访谈到主页怎么做,apache服务试验笔记

关键词: