Web服务器——Apache
来源:互联网 发布:西门子840d基础编程 编辑:程序博客网 时间:2024/05/11 04:30
一 Web服务器相关知识
Web服务器是Linux最常用的应用。Web服务器是一种BS结构,亦即浏览器/服务器模式,具有通用性,是CS(客户端/服务器)结构的一种抽象。Web服务器通常采用HTTP协议,亦即超文本传输协议。动态语言的发展从CGI到以后的JSP、PHP、ASP.NET,后面几种技术现在得到了广泛地应用。Apache服务器是由Apache基金会开发、运行和维护的一种Web服务器,本身支持PHP,对应的访问名是httpd。为了支持JSP,在apache的基础上进行改善,出现了tomcat,也就是Apache的加强版。想必读者非常清楚,Java体系被分为J2SE(Java Standard Edition)、J2EE(Java Enterprise Edition,包括JSP、Servlet、EJB、JNDI、Struts、Hibernate、Spring等技术)、J2ME(Java Micro Edition)。其他公司也出现了可以支持Java技术的Web服务器,比如Jboss,现属于RedHat(三大产品线:Linux系统、虚拟机、JBoss),BEA公司的WebLogic,IBM公司的Websphere等等。当然Windows下支持ASP.NET的Web服务器有微软的IIS。
二 什么是Apache
Apache,当今市场上主流的Web服务器。Apache基本配置文件的httpd.conf。apache可以和php集成。
三 apache安装及参数讲解
- #安装
- [root@serv01 ~]# yum install httpd -y
- [root@serv01 ~]# rpm -qa|grep httpd
- httpd-tools-2.2.15-9.el6.x86_64
- httpd-2.2.15-9.el6.x86_64
- [root@serv01 ~]# rpm -ql httpd|grep conf
- /etc/httpd/conf
- /etc/httpd/conf.d
- /etc/httpd/conf.d/README
- /etc/httpd/conf.d/welcome.conf
- /etc/httpd/conf/httpd.conf
- /etc/httpd/conf/magic
- /etc/sysconfig/httpd
- /usr/lib64/httpd/modules/mod_log_config.so
- [root@serv01 ~]# cd /etc/httpd/
- [root@serv01 httpd]# ll
- total 8
- drwxr-xr-x. 2 root root 4096 Aug 14 22:18conf
- drwxr-xr-x. 2 root root 4096 Aug 14 22:18 conf.d
- lrwxrwxrwx. 1 root root 19 Aug 14 22:18 logs ->../../var/log/httpd
- lrwxrwxrwx. 1 root root 29 Aug 14 22:18 modules ->../../usr/lib64/httpd/modules
- lrwxrwxrwx. 1 root root 19 Aug 14 22:18 run ->../../var/run/httpd
- [root@serv01 httpd]# ls conf.d/
- README welcome.conf
- [root@serv01 httpd]# ls logs/
- access_log error_log
- URL:http://httpd.apache.org/docs/2.2/
- /etc/httpd/conf/httpd.conf
- #参数ServerTokens
- 浏览器访问:http://192.168.1.11/aaa.html
- ServerTokens OS
- Not Found
- The requested URL /aaa.html wasnot found on this server.
- Apache/2.2.15 (Red Hat)Server at 192.168.1.11 Port 80
- ServerTokens major
- Not Found
- The requested URL /aaa.html wasnot found on this server.
- Apache/2 Server at192.168.1.11 Port 80
- ServerTokens full
- Not Found
- The requested URL /aaa.html wasnot found on this server.
- Apache/2.2.15 (Red Hat)DAV/2 Server at 192.168.1.11 Port 80
- #根目录
- ServerRoot "/etc/httpd"
- #PID
- PidFile run/httpd.pid
- #连接超时
- Timeout 60
- #不支持有状态连接
- KeepAlive Off
- #KeepAlive ON时生效,最大请求连接的时间
- MaxKeepAliveRequests 100
- #两次请求之间的延时
- KeepAliveTimeout 15
- #MPM:多路处理模块
- #prefork worker
- #处理请求两种方式:进程 线程
- #进程:prefork 每个用户启动一个进程,一个进程处理一个客户端 安全好
- #worker:线程处理每个连接,一个进程中有多个线程 性能好
- #RPM包不支持worker,源码编译
- # prefork MPM
- # StartServers: number of server processes tostart
- # MinSpareServers: minimum number of serverprocesses which are kept spare
- # MaxSpareServers: maximum number of serverprocesses which are kept spare
- # ServerLimit: maximum value for MaxClientsfor the lifetime of the server
- # MaxClients: maximum number of serverprocesses allowed to start
- # MaxRequestsPerChild: maximum number ofrequests a server process serves
- <IfModule prefork.c>
- #启动服务器时的进程数目
- StartServers 8
- #最小空闲进程
- MinSpareServers 5
- #最大空闲进程
- MaxSpareServers 20
- #服务器限制 ServerLimit MaxClients保持一致
- ServerLimit 256
- #最多支持客户端访问
- MaxClients 256
- #最大的请求数量
- MaxRequestsPerChild 4000
- </IfModule>
- [root@serv01 conf]# ps -ef|grep http
- root 1341 1 0 22:44 ? 00:00:00 /usr/sbin/httpd
- apache 1343 1341 0 22:44 ? 00:00:00 /usr/sbin/httpd
- apache 1344 1341 0 22:44 ? 00:00:00 /usr/sbin/httpd
- apache 1345 1341 0 22:44 ? 00:00:00 /usr/sbin/httpd
- apache 1346 1341 0 22:44 ? 00:00:00 /usr/sbin/httpd
- apache 1347 1341 0 22:44 ? 00:00:00 /usr/sbin/httpd
- apache 1348 1341 0 22:44 ? 00:00:00 /usr/sbin/httpd
- apache 1349 1341 0 22:44 ? 00:00:00 /usr/sbin/httpd
- apache 1350 1341 0 22:44 ? 00:00:00 /usr/sbin/httpd
- root 1351 1149 0 22:44 pts/0 00:00:00 vim httpd.conf
- root 1360 1266 0 22:58 pts/1 00:00:00 grep http
- # worker MPM
- # StartServers: initial number of serverprocesses to start
- # MaxClients: maximum number of simultaneousclient connections
- # MinSpareThreads: minimum number of workerthreads which are kept spare
- # MaxSpareThreads: maximum number of workerthreads which are kept spare
- # ThreadsPerChild: constant number of workerthreads in each server process
- # MaxRequestsPerChild: maximum number ofrequests a server process serves
- <IfModule worker.c>
- #开始启动的
- StartServers 4
- #最小大的客户端
- MaxClients 300
- #每个进程最小支持的线程
- MinSpareThreads 25
- #每个进程最大支持的线程
- MaxSpareThreads 75
- #每个服务进程支持的线程数
- ThreadsPerChild 25
- #最大的服务次数,为0不限制
- MaxRequestsPerChild 0
- </IfModule>
- [root@serv01 conf]# httpd -l
- Compiled in modules:
- core.c
- prefork.c
- http_core.c
- mod_so.c
- #监听
- Listen 80
- [root@serv01 conf]# netstat -langput|grephttpd
- tcp 0 0 :::80 :::* LISTEN 2414/httpd
- http://192.168.1.11:8080/
- [root@serv01 conf]# netstat -langput|grephttpd
- tcp 0 0 :::8080 :::* LISTEN 2437/httpd
- #动态加载模块
- LoadModule
- #包含文件
- Include conf.d/*.conf
- #运行进程的用户
- User apache
- #运行进程的用户组
- Group apache
- [root@serv01 conf]# ps -ef|grep http
- root 2510 1 0 23:28 ? 00:00:00 /usr/sbin/httpd
- larry 2512 2510 0 23:28 ? 00:00:00 /usr/sbin/httpd
- larry 2513 2510 0 23:28 ? 00:00:00 /usr/sbin/httpd
- larry 2514 2510 0 23:28 ? 00:00:00 /usr/sbin/httpd
- larry 2515 2510 0 23:28 ? 00:00:00 /usr/sbin/httpd
- larry 2516 2510 0 23:28 ? 00:00:00 /usr/sbin/httpd
- larry 2517 2510 0 23:28 ? 00:00:00 /usr/sbin/httpd
- larry 2518 2510 0 23:28 ? 00:00:00 /usr/sbin/httpd
- larry 2519 2510 0 23:28 ? 00:00:00 /usr/sbin/httpd
- root 2521 1266 0 23:28 pts/1 00:00:00 grep http
- #如果用户不存在,会报错
- [root@serv01 conf]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Starting httpd: httpd: bad user name justdb
- [FAILED]
- #服务器邮件地址
- ServerAdmin root@localhost
四 启动不报警告解决
- [root@serv01 conf]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Starting httpd: httpd:apr_sockaddr_info_get() failed for serv01.host.com
- httpd: Could not reliably determine theserver's fully qualified domain name, using 127.0.0.1 for ServerName
- [ OK ]
- [root@serv01 conf]# vim httpd.conf
- [root@serv01 conf]# cat httpd.conf |grepServerName
- # ServerName gives the name and port that theserver uses to identify itself.
- #ServerName www.example.com:80
- ServerName serv01.host.com
- # ServerName directive.
- # ServerName dummy-host.example.com
- [root@serv01 conf]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Starting httpd: [ OK ]
五 Web根目录和别名设置
- #别名:Alias 真实路径不在Web根目录下
- --第一步,修改DocumentRoot
- [root@serv01 conf]# cat httpd.conf | grepDocumentRoot
- DocumentRoot "/web"
- Alias /upload "/upload"
- Alias /up "/upload"
- --第二步,创建测试文件
- [root@serv01 conf]# mkdir /web
- [root@serv01 conf]# vim /web/index.html
- [root@serv01 conf]# cat /web/index.html
- this is index.html
- [root@serv01 conf]# mkdir /upload
- [root@serv01 conf]# mkdir /web/upload/
- [root@serv01 conf]# vim /upload/index.html
- [root@serv01 conf]# cat /upload/index.html
- this is /upload index.html
- [root@serv01 conf]# vim/web/upload/index.html
- [root@serv01 conf]# cat/web/upload/index.html
- this is /web/upload/ index.html
- --第三步,设置别名
- [root@serv01 conf]# tail -n1 httpd.conf
- Alias /up "/upload"
- [root@serv01 conf]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Starting httpd: [ OK ]
- --第四步,测试
- 浏览器输入:http://192.168.1.11/up/, 页面显示this is /upload index.html;浏览器输入http://192.168.1.11/,页面显示this is index.html;浏览器输入http://192.168.1.11/upload,页面显示this is /web/upload/ index.html
六 对目录权限的限制
- <Directory />
- Options FollowSymLinks
- AllowOverride None
- </Directory>
- #配置文件中,关键字不区分大小写
- <directory "/upload"/>
- Option Indexes FollowSymLinks
- </directory>
- #假如文件夹下没有index文件,那么以文件列表显示
- Indexes
- #显示软链接文件
- FollowSymLinks
- #如果没有index.html文件,则不显示(Forbidden)
- None
- [root@serv01 conf]# tail -n5 httpd.conf
- Alias /up "/upload"
- <directory "/upload">
- OptionsIndexes FollowSymLinks
- </directory>
- [root@serv01 conf]# cd /upload/
- [root@serv01 upload]# mkdir user
- [root@serv01 upload]# cp /boot/* user/
- oot@serv01 user]# cd /
- [root@serv01 /]# dd if=/dev/zero of=aa01.isobs=1M count=5
- 5+0 records in
- 5+0 records out
- 5242880 bytes (5.2 MB) copied, 0.0260953 s,201 MB/s
- [root@serv01 /]# cd -
- /upload/user
- [root@serv01 user]# ln -s /aa01.iso aa01.iso
- [root@serv01 conf]# vim httpd.conf
- [root@serv01 conf]# tail -n5 httpd.conf
- Alias /up "/upload"
- <directory "/upload">
- Optionsnone FollowSymLinks
- </directory>
- [root@serv01 conf]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Starting httpd: [ OK ]
- #子目录继承上级目录的权限
- [root@serv01 conf]# tail -n5 httpd.conf
- Alias /up "/upload"
- <directory "/upload/user">
- OptionsIndexes FollowSymLinks
- </directory>
七 参数AllowOverride做权限控制 all(授权用户)
- AllowOverride all
- AllowOverride
- --第一步,编辑httpd.conf文件,加入AllowOverride参数,并设置成all
- [root@serv01 conf]# vim httpd.conf
- [root@serv01 conf]# tail -n6 httpd.conf
- Alias /up "/upload"
- <directory "/upload/user">
- OptionsIndexes FollowSymLinks
- AllowOverrideall
- </directory>
- --第二步,在限制的文件夹里新建.htaccess文件,编辑如下内容
- [root@serv01 user]# vim .htaccess
- [root@serv01 user]# cat .htaccess
- authuserfile"/etc/httpd/conf/htpasswd"
- authtype basic
- authname "please input your name andpassword"
- require valid-user
- [root@serv01 user]# pwd
- /upload/user
- --第三步,创建测试用户,这里创建的用户根系统帐号无关,所以无需配置成系统用户
- [root@serv01 user]# htpasswd -c/etc/httpd/conf/htpasswd justdb
- New password:
- Re-type new password:
- Adding password for user justdb
- --第四步,重启服务
- [root@serv01 conf]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Starting httpd: [ OK ]
- --第五步,测试
- http://192.168.1.11/up/user/
八 网段IP限制
- #先允许,后禁止,那么192.168.1.1不能访问
- Order Allow,Deny
- Allow from 192.168.1.1
- Deny from all
- #先禁止,后允许,那么192.168.1.1可以访问
- Order Deny,Allow
- Allow from 192.168.1.1
- Deny from all
- [root@serv01 conf]# tail -n11 httpd.conf
- Alias /up "/upload"
- <directory "/upload/user">
- OptionsIndexes FollowSymLinks
- AllowOverrideall
- OrderAllow,Deny
- Allowfrom 192.168.1.1
- #Denyfrom 192.168.1.1
- #Denyfrom all
- #Allowfrom 192.168.1.0/24
- </directory>
九 用户个性化主页
- --第一步,修改配置文件
- [root@serv01 conf]# vim httpd.conf
- [root@serv01 conf]# cat httpd.conf |grepUserDir -n
- 351:# UserDir: The name of the directory thatis appended onto a user's home
- 364: # UserDir is disabled by default since it can confirm the presence
- 368: #UserDir disabled
- 372: # directory, remove the "UserDir disabled" line above, anduncomment
- 375: UserDir public_html
- 380:# Control access to UserDirdirectories. The following is an example
- #
- # Control access to UserDir directories. The following is an example
- # for a site where these directories arerestricted to read-only.
- #
- #以下可以打开或者保持注释,都可以正常完成功能
- <Directory /home/*/public_html>
- AllowOverride FileInfo AuthConfig Limit
- Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
- <Limit GET POST OPTIONS>
- Order allow,deny
- Allow from all
- </Limit>
- <LimitExcept GET POST OPTIONS>
- Order deny,allow
- Deny from all
- </LimitExcept>
- </Directory>
- --第二步,添加用户
- [root@serv01 home]# useradd larry01
- [root@serv01 home]# useradd larry02
- [root@serv01 home]# useradd larry03
- --第三步,进入用户主目录,分别创建public_html文件夹,然后分别创建index.html文件,内容如下
- [root@serv01 home]# cd larry01
- [root@serv01 larry01]# mkdir public_html
- [root@serv01 public_html]# vim index.html
- [root@serv01 public_html]# cat/home/larry01/public_html/index.html
- this is larry01 home dir
- [root@serv01 home]# cd larry02
- [root@serv01 larry01]# mkdir public_html
- [root@serv01 public_html]# vim index.html
- [root@serv01 public_html]# cat/home/larry02/public_html/index.html
- this is larry02 home dir
- [root@serv01 home]# cd larry03
- [root@serv01 larry01]# mkdir public_html
- [root@serv01 public_html]# vim index.html
- [root@serv01 public_html]# cat/home/larry03/public_html/index.html
- this is larry03 home dir
- --第四步,修改家录权限(755或者777或者711,只需要有x的权限即可)
- [root@serv01 public_html]# chmod 755/home/larry01
- [root@serv01 public_html]# ll -d/home/larry01
- drwxr-xr-x. 4 larry01 larry01 4096 Aug 1517:56 /home/larry01
- [root@serv01 public_html]# chmod 755/home/larry02
- [root@serv01 public_html]# ll -d/home/larry02
- drwxr-xr-x. 4 larry01 larry02 4096 Aug 1517:56 /home/larry02
- [root@serv01 public_html]# chmod 755/home/larry03
- [root@serv01 public_html]# ll -d/home/larry03
- drwxr-xr-x. 4 larry01 larry03 4096 Aug 1517:56 /home/larry03
- --第五步,重启服务
- [root@serv01 conf]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Starting httpd: [ OK ]
- --第六步,测试
- 输入:http://192.168.1.11/~larry01/
- 浏览器显示:this is larry01 home dir
- 输入:http://192.168.1.11/~larry02/
- 浏览器显示:this is larry02 home dir
- 输入:http://192.168.1.11/~larry03/
- 浏览器显示:this is larry03 home dir
十 其他参数
- #主页是index.html index.html.var的参数控制
- DirectoryIndex index.html index.html.var
- #用户访问控制的文件名
- AccessFileName .htaccess
- #对文件的限制,拒绝访问.htaccess文件
- <Files ~ "^\.ht">
- Order allow,deny
- Deny from all
- Satisfy All
- </Files>
- #类型配置文件
- TypesConfig /etc/mime.types
- #Web服务器支持传送的文件类型
- [root@serv01 public_html]# cat/etc/mime.types
- #默认类型
- DefaultType text/plain
- #错误日志文件存放位置
- ErrorLog logs/error_log
- #日志警告级别
- LogLevel warn
- #日志格式,后面的名字用于引用
- LogFormat "%h %l %u %t\"%r\" %>s %b \"%{Referer}i\"\"%{User-Agent}i\"" combined
- LogFormat "%h %l %u %t \"%r\"%>s %b" common
- LogFormat "%{Referer}i -> %U" referer
- LogFormat "%{User-agent}i" agent
- #自定义日志格式
- CustomLog logs/access_log combined
- #服务器签名
- ServerSignature On
- #别名
- Alias /icons/ "/var/www/icons/"
- #语言支持
- AddLanguage ca .ca
- BrowserMatch "Mozilla/2"nokeepalive
- BrowserMatch "MSIE 4\.0b2;"nokeepalive downgrade-1.0 force-response-1.0
- BrowserMatch "RealPlayer 4\.0"force-response-1.0
- BrowserMatch "Java/1\.0"force-response-1.0
- BrowserMatch "JDK/1\.0"force-response-1.0
- #错误的记录目录
- Alias /error/ "/var/www/error/"
十一 CGI示例
- --第一步,查看配置文件,不需要任何修改
- ScriptAlias /cgi-bin/"/var/www/cgi-bin/"
- --第二步,进入/var/www/cgi-bin/目录,编辑一个可执行的脚本
- [root@serv01 public_html]# cd/var/www/cgi-bin/
- [root@serv01 cgi-bin]# ll
- total 0
- [root@serv01 cgi-bin]# vim test.sh
- [root@serv01 cgi-bin]# chmod a+x ./*
- [root@serv01 cgi-bin]# cat test.sh
- #!/bin/bash
- echo "Content-type:text/html"
- #小写亦可
- echo "content-type:text/html"
- echo ""
- echo "hello,world"
- [root@serv01 cgi-bin]# vim test.sh
- [root@serv01 cgi-bin]# cat test.sh
- #!/bin/bash
- echo "Content-type:text/html"
- echo ""
- #echo "hello,world"
- ps -ef
- --第三步,测试
- http://192.168.1.11/cgi-bin/test.sh
十二 浏览器调用C语言程序
- --第一步,编写C语言程序
- [root@serv01 cgi-bin]# vim main.c
- [root@serv01 cgi-bin]# cat main.c
- #include <stdio.h>
- int main(void)
- {
- printf("Context-type:text/html\n\n\n");
- printf("helloworld!!!\n");
- return0;
- }
- --第二步,安装gcc和c++相关的rpm包
- [root@serv01 cgi-bin]# yum install gcc c++*-y
- --第三步,编译
- [root@serv01 cgi-bin]# gcc main.c -o main
- [root@serv01 cgi-bin]# ./main
- Context-type:text/html
- hello world!!!
- --第四步,测试
- http://192.168.1.11/cgi-bin/main
- hello world!!!
十三 虚拟主机——不同的域名访问不同的主页——域名实现
#一个apache实现多个域名,www.larrywen.com和www.justdb.com
有三种实现方式,通过域名、IP地址和端口。其中基于域名实现虚拟主机最常用。
- #不同的域名访问不同的主页——域名实现
- --第一步,搭建DNS
- --1.安装DNS相关RPM包
- [root@serv02 ~]# yum install bind* -y
- --2.编辑named.conf和named.rfc1912.zones文件
- [root@serv02 etc]# vim named.conf
- [root@serv02 etc]# vim named.rfc1912.zones
- [root@serv02 named]# cat /etc/named.conf
- options {
- listen-onport 53 { any; };
- allow-query { any; };
- };
- [root@serv02 named]# tail -n11/etc/named.rfc1912.zones
- zone "larrywen.com" IN {
- type master;
- file "larrywen.com.zone";
- allow-update { none; };
- };
- zone "justdb.com" IN {
- type master;
- file "justdb.com.zone";
- allow-update { none; };
- };
- --3.编辑larrywen.com.zone和justdb.com.zone文件
- [root@serv02 named]# cp named.localhostlarrywen.com.zone -a
- [root@serv02 named]# vim larrywen.com.zone
- [root@serv02 named]# cp named.localhostjustdb.com.zone -a
- [root@serv02 named]# vim justdb.com.zone
- [root@serv02 named]# cat larrywen.com.zone
- $TTL 1D
- @ INSOA dns.larrywen.com. root.larrywen.com.(
- 0 ; serial
- 1D ; refresh
- 1H ; retry
- 1W ; expire
- 3H) ; minimum
- NS dns.larrywen.com.
- dns IN A 192.168.1.12
- www IN A 192.168.1.11
- [root@serv02 named]# cat justdb.com.zone
- $TTL 1D
- @ INSOA dns.justdb.com. root.justdb.com. (
- 0 ; serial
- 1D ; refresh
- 1H ; retry
- 1W ; expire
- 3H) ; minimum
- NS dns.justdb.com.
- dns IN A 192.168.1.12
- www IN A 192.168.1.11
- --4.重启服务
- [root@serv02 named]# /etc/init.d/named start
- Starting named: [ OK ]
- --5.虚拟机做测试,安装bind-utils
- [root@serv01 cgi-bin]# yum install bind-utils-y
- [root@serv01 cgi-bin]# vim /etc/resolv.conf
- [root@serv01 cgi-bin]# cat /etc/resolv.conf
- nameserver 192.168.1.12
- [root@serv01 cgi-bin]# dig www.larrywen.com+short
- 192.168.1.11
- [root@serv01 cgi-bin]# dig www.justdb.com+short
- 192.168.1.11
- --第二步,修改配置文件httpd.conf
- [root@serv01 conf]# cat httpd.conf
- NameVirtualHost *:80
- <VirtualHost *:80>
- ServerAdmin root@larrywen.com
- DocumentRoot /larrywen
- ServerName www.larrywen.com
- ErrorLog logs/dummy-host.larrywen.com-error_log
- CustomLog logs/dummy-host.larrywen.com-access_log common
- </VirtualHost>
- <VirtualHost *:80>
- ServerAdmin root@justdb.com
- DocumentRoot /justdb
- ServerName www.justdb.com
- ErrorLog logs/dummy-host.justdb.com-error_log
- CustomLog logs/dummy-host.justdb.com-access_log common
- </VirtualHost>
- --第三步,真实机加上DNS解析
- [root@larrywen 0815]# echo "nameserver192.168.1.12" > /etc/resolv.conf
- [root@larrywen 0815]# cat /etc/resolv.conf
- nameserver 192.168.1.12
- #真实机做测试
- [root@larrywen 0815]# dig www.larrywen.com+short
- 192.168.1.11
- [root@larrywen 0815]# dig www.justdb.com+short
- 192.168.1.11
- --第四步,虚拟机(Serv01)重启服务
- [root@serv01 conf]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Starting httpd: [ OK ]
- --第五步,测试
- http://www.justdb.com/
- http://www.larrywen.com/
十四 虚拟主机——不同的IP地址访问不同的主页——IP地址实现
- 192.168.1.11对应http://www.larrywen.com/
- 172.16.1.11对应http://www.justdb.com/
- --第一步,添加网卡,修改IP地址
- [root@serv01 cgi-bin]# ifconfig eth1172.16.1.11 netmask 255.255.255.0
- [root@serv01 cgi-bin]# ifconfig eth1|grep"inet addr"
- inet addr:172.16.1.11 Bcast:172.16.1.255 Mask:255.255.255.0
- --第二步,修改配置文件
- [root@serv01 conf]# vim httpd.conf
- [root@serv01 conf]# cat httpd.conf
- #<VirtualHost *:80>
- <VirtualHost 192.168.1.11:80>
- DocumentRoot /larrywen
- ServerName serv01.host.com
- </VirtualHost>
- <VirtualHost 172.16.1.11:80>
- DocumentRoot /justdb
- ServerName serv01.host.com
- </VirtualHost>
- --第三步,重启服务
- [root@serv01 conf]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Starting httpd: [ OK ]
- --第四步,测试
- http://192.168.1.11
- this is larrywen
- http://172.16.1.11/
- this is justdb
十五 虚拟主机——不同的IP地址访问不同的主页——端口实现
- --第一步,修改配置文件
- [root@serv01 conf]# cat httpd.conf
- Listen 80
- Listen 8080
- <VirtualHost *:80>
- DocumentRoot /larrywen
- </VirtualHost>
- <VirtualHost *:8080>
- DocumentRoot /justdb
- </VirtualHost>
- [root@serv01 conf]# netstat -lanput|grephttpd
- tcp 0 0 :::8080 :::* LISTEN 1950/httpd
- tcp 0 0 :::80 :::* LISTEN 1950/httpd
- --第二步,重启服务
- [root@serv01 conf]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Starting httpd: [ OK ]
- --第三步,测试
- http://192.168.1.11/
- this is larrywen
- http://192.168.1.11:8080/
- this is justdb
0 0
- Web服务器——Apache
- Web服务器——Apache
- 在树莓派上搭建web服务器——基于Apache
- web服务器性能测试之利器—apache的ab
- Apache服务器的配置具体操作—— Apache比较强大,所以要配置Apache作为本地web服务器
- Linux Apache Web 服务器
- Linux Apache Web 服务器
- Web服务器软件Apache
- Linux Apache Web 服务器
- 搭建Web服务器Apache
- 调查Apache Web服务器
- Apache构建WEB服务器
- apache web服务器移植
- web服务器--apache
- apache(Web服务器)
- apache web 服务器
- Apache WEB服务器详解
- 我学你也学之WEB服务器篇——安装JDK和APACHE服务器
- 一年一年,成长就好
- NIO与IO的区别
- word 批量选取相同格式的内容
- 你不知道的JavaScript用法,Hacker是这样写JS的
- 设计模式的三大类别
- Web服务器——Apache
- CUGB专题训练之数据结构:A - Balanced Lineup(线段树单点或RMQ)
- android默认输入法设置
- zedboard中使用mio,emio和axi_gpio点灯
- 二叉树中节点的最大距离
- ios hover problem【iphone和ipad hover态不消失问题】
- Java动态代理之CGLIB
- eclipse新建Android项目时提示AndroidManifest.xml file missing!
- cuda-convnet 的运行环境设置