澳门新浦京娱乐场网站-www.146.net-新浦京娱乐场官网
做最好的网站

澳门新浦京娱乐场网站:apache服务实验笔记,L

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 U帕杰罗L:统一财富一定 合同 域名:端口 网页文件名

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
澳门新浦京娱乐场网站:apache服务实验笔记,Linux配置虚拟主机后。注释掉。

  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,

    澳门新浦京娱乐场网站:apache服务实验笔记,Linux配置虚拟主机后。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,搭建多少个网址,种种网址采用区别域名访谈

 

 

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>
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 重写作用   U途乐L

在UPRADOL中输入三个地点,会自行跳转为另二个

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     最加纳Ake拉接数 *

httpd-multilang-errordoc.conf 错页面 *

httpd-ssl.conf    ssl避孕套接字访问

httpd-userdir.conf 顾客主目录配置

httpd-vhosts.conf 虚构主机

 

本文由澳门新浦京娱乐场网站发布于www.146.net,转载请注明出处:澳门新浦京娱乐场网站:apache服务实验笔记,L