首页 技术 正文
技术 2022年11月18日
0 收藏 641 点赞 4,272 浏览 3607 个字

1. 修改httpd.conf文件# vi  /usr/local/apache/conf/httpd.conf1) 设置根目录的路径根目录是指Apache存放配置文件和日志文件的目录,配置参数为ServerRoot,默认位于“/usr/local/apache”。命令如下: ServerRoot /usr/local/apache2) 设置监听IP地址及端口号默认侦听本机所有IP地址的TCP80端口,命令如下:Listen 80用户也可以按自己的需求,使用多个Listen语句在多个地址和端口上侦听客户端请求。比如:Listen 192.168.99.9:80Listen 172.16.0.20:80803) 设置系统管理员E-mail使用ServerAdmin参数设置管理员E-mail,比如管理员的Email地址为root@guoxuemin.cn: ServerAdmin root@guoxuemin.cn4) 设置服务器主机的名称参数ServerName用来设置服务器的主机名称,如果没有域名则填入服务器的IP地址,比如服务器的IP地址为192.168.99.9:80 ServerName 192.168.99.9:805) 设置主目录的路径用户可以使用参数DocumentRoot配置服务器主目录默认路径,比如,主目录路径为: DocumentRoot /usr/local/apache/htdocs6) 设置默认文件Apache的默认文件名为index.html,可以使用Directory Index参数来配置,比如,将index.php设置为默认文件名: <IfModulf dir_moudle>Directory Index index.html</IfModulf>7)测试:打开浏览器,输入地址:http://192.168.99.9,可以打开站点了:  2. 配置目录权限使用<Directory 目录路径>和</Directory>设置目录的权限。比如:<Directory  “/var/www/icons”>Options  Indexes  MultiViewsAllowOverride  NoneOrder  allow,denyAllow  from  all</Directory>说明:1)定义目录特性选项Options可选参数:Indexes:该特性表明目录允许“目录浏览”;MultiViews:该特性表明目录允许内容协商的多重试图;All:包含了除MultiViews外的所有特性;ExecCGI:该特性表明允许在该目录下执行CGI脚本;FollowSymLinks:该特性表明允许在该目录下使用符号连接。2).htaccess文件可以通过.htaccess文件(访问控制文件)设置目录的权限。AccessFileName  .htaccess配置参数AllowOverride指定目录的.htaccess文件中指令的类型,包括All、None与Options、FileInfo、AuthConfig、Limit的任意组合。一般将AllowOverride设置为“None”,禁止使用.htaccess文件,当AllowOverride参数为All时,.htaccess文件可以覆盖任何以前的配置。3)设置访问控制使用Order选项来定义访问权限。比如以下语句表明允许所有客户机的访问:Order  allow,denyAllow  from  all以下语句表明只允许网段192.168.99.0/24的客户机访问,但IP地址为192.168.99.254这个客户机除外:Order  allow,denyAllow from  192.168.99.0/24Deny from  192.168.99.254用户可以根据需要,按上述方法配置自己的目录权限。 3. 创建虚拟目录使用Alias选项创建虚拟目录,比如,建立“/icons/”这个虚拟目录,其对应的物理路径为“/var/www/icons/”:Alias  /icons/  “/var/www/icons/” 4. 用户认证比如,有一个名为myweb的虚拟目录,其对应的物理路径是“/usr/local/myweb”,现对其启用用户认证功能,只允许用户Tonyguo和Wayne访问。1)建立虚拟目录并设置用户认证: 2) 建立口令文件并为用户设置口令 -c选项表示无论口令文件是否已经存在,都会重新写入文件并删除原内容。所以第二个用户wayne不需要使用-c选项。3)测试在浏览器中输入:http://192.168.99.9/myweb,可以看到如下对话框: 输入用户名和密码后就可以访问网站了:  三、配置虚拟主机1. 配置基于IP的虚拟主机1)IP地址相同,但端口号不同的虚拟主机配置比如使用192.168.99.9的两个不同端口80和8080发布两个不同站点, 虚拟主机分别对应的目录为/usr/local/apache/htdocs/web1和/usr/local/apache/htdocs/web2:Listen 80Listen 8080<VirtualHost  192.168.99.9:80>  ServerSignature  email  DocumentRoot  /usr/local/apache/htdocs/web1  DirectoryIndex  index.html  index.htm  LogLevel  warm  HostNameLookups  off</VirtualHost><VirtualHost  192.168.99.9:8080>  ServerSignature  email  DocumentRoot  /usr/local/apache/htdocs/web2  DirectoryIndex  index.html  index.htm  LogLevel  warm  HostNameLookups  off</VirtualHost>2)配置基于域名的虚拟主机比如服务器有两个IP地址192.168.99.9和192.168.99.10,使用这两个IP创建两台虚拟主机,虚拟主机分别对应的目录为/usr/local/apache/htdocs/web1和/usr/local/apache/htdocs/web2。设置方法如下:<VirtualHost  192.168.99.9>  ServerName  192.168.99.9:80  DocumentRoot  /usr/local/apache/htdocs/web1  DirectoryIndex  index.html  index.htm</VirtualHost><VirtualHost  192.168.99.10>  ServerName  192.168.99.10:80  DocumentRoot  /usr/local/apache/htdocs/web2  DirectoryIndex  index.html  index.htm</VirtualHost> 2. 配置基于域名的虚拟主机比如有两个域名guoxuemin.cn和tonyguo.com需要使用同一台服务器192.168.99.9,那么可以这样配置:NameVirtualHost  192.168.99.9<VirtualHost  www.guoxuemin.cn>  ServerName  www.guoxuemin.cn:80  ServerAdmin  admin@guoxuemin.cn  DocumentRoot  /usr/local/apache/htdocs/web1  DirectoryIndex  index.html  index.htm  ErrorLog  logs/web1/error_log  Customlog  logs/web1/access_log  combined</VirtualHost><VirtualHost  www.tonyguo.com>  ServerName  www.tonyguo.com:80  ServerAdmin  admin@tonyguo.com DocumentRoot  /usr/local/apache/htdocs/web2  DirectoryIndex  index.html  index.htm  ErrorLog  logs/web1/error_log  Customlog  logs/web1/access_log  combined</VirtualHost>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,024
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,514
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,362
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,143
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,776
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,854