当前位置: 代码迷 >> Web前端 >> apache(web服务器)的筹建
  详细解决方案

apache(web服务器)的筹建

热度:389   发布时间:2012-09-27 11:11:17.0
apache(web服务器)的搭建
apache(web服务器)
安装包
httpd-2.2.3-43.el5.i386.rpm
httpd-manual-2.2.3-43.el5.i386.rpm (帮助文档)
启动服务
service httpd restart
端口
80 443    //浏览器默认访问的是80端口,当用到https的时候,默认访问的是443端口
数据目录
/var/www/html
配置文件
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/

netstat -anplt
nmap 192.168.2.254
vim /etc/services
arping 192.168.2.249    //在一台主机ping一个地址,如果出现了两个make地址,那么就说有ip地址冲突
arp

基于用户家目录发布网页
1.vim /etc/httpd/conf/httpd.conf
<IfModule mod_userdir.c>
UserDir public_html
</IfModule>
2.useradd robin
  useradd eric
  mkdir /home/robin/public_html
  mkdir /home/eric/public_html
  echo 'I am robin' >> /home/robin/public_html/index.html
  echo 'I am eric' >> /home/eric/public_html/index.html
  chmod 757 /home/eric /home/robin
测试
http://192.168.2.254/~robin/
http://192.168.2.254/~eric/

发布目录
alias /down /var/ftp/  别名
<directory /var/ftp>
        options indexes
order deny,allow
allow from all
   deny from all
</directory>

发布cgi脚本
脚本
cd /var/www/cgi-bin/
touch aa.sh
vim  aa.sh
#!/bin/bash
echo -e "content-type: text/html\n"
uname -a
echo "<br>"
date +%F%T

访问
http://192.168.2.254/cgi-bin/aa.sh

验证方式访问
alias /down /var/ftp/
<directory /var/ftp>
        options indexes
        AuthType Basic
        AuthName "welcome to uplooking!!!!!!!"
        AuthBasicProvider file
        AuthUserFile /etc/httpd/conf/passwdb
        Require user robin
#Require valid-user
</directory>

htpasswd -c -b /etc/httpd/conf/passwdb robin 123
htpasswd -b  /etc/httpd/conf/passwdb eric 123

访问
http://192.168.2.254/down


基于域名的虚拟主机
1.vim /etc/hosts
192.168.2.254   www.sina.com
192.168.2.254   www.sohu.com

2.vim /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
<VirtualHost *:80>
        servername www.sina.com
        DocumentRoot /var/www/sina
</VirtualHost>
<VirtualHost *:80>
        servername www.sohu.com
        DocumentRoot /var/www/sohu
</VirtualHost>

3.cd /var/www
mkdir sina
mkdir sohu
echo sina >> sina/index.html
echo sohu >> sohu/index.html

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



基于ip的虚拟主机
1.vim /etc/hosts
192.168.2.254   www.sina.com
10.10.10.254   www.sohu.com

2.vim /etc/httpd/conf/httpd.conf

<VirtualHost 192.168.2.254:80>
        servername www.sina.com
        DocumentRoot /var/www/sina
</VirtualHost>
<VirtualHost 10.10.10.254:80>
        servername www.sohu.com
        DocumentRoot /var/www/sohu
</VirtualHost>

3.cd /var/www
mkdir sina
mkdir sohu
echo sina >> sina/index.html
echo sohu >> sohu/index.html

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


以上为仅供参考,如有问题,欢迎大家提出建议和意见。
  相关解决方案