欢迎来访~

使用Apache搭建Web网站服务器

1.Web 服务器的工作模式和端口
工作模式是:B/S 模式
工作端口是:80/http 正常端口
                    443/https SSL 端口
 
2.安装服务器端:httpd
yum install httpd
yum install httpd-devel
 
3.配置文件位置
/etc/httpd/conf/httpd.conf
 
4.配置文件简要介绍
 
[root@hello2099 ~]# vim /etc/httpd/conf/httpd.conf 
 
ServerName 192.168.1.13:80                   #服务器主机名
PidFile run/httpd.pid                               #运行进程 ID 存放
Timeout 60                                              #超时时间,多少秒没有反应就超时
KeepAlive Off                                          #是否允许一个永久的链接,为 ON 时,可以提高传输文件效率,建议开启
MaxKeepAliveRequests 100                    #设置为ON时,客户端每次连接允许请求相应最大文件数,默认100个
KeepAliveTimeout 15                              #超时时间,同一个客户端下一个请求 15s 没收到就超时
Listen 80                                                  #监听端口,默认本地 IP,如果指定 ip 写上 IP:80
<IfModule prefork.c>
StartServers 8                                         #服务开始起启动 8 个进程
MinSpareServers 5                                 #最小空闲 5 个进程
MaxSpareServers 20                              #最多空闲 20 个进程
ServerLimit 256                                      #服务器允许配置进程数上线
MaxClients 256                                      #最大连接数 256,超过要进入等候队列
MaxRequestsPerChild4000                    #每个进程生存期内服务最大的请求数量,0 表示用不结束
</IfModule>
<Directory />
Options FollowSymLinks                        #Options Indexes 目录浏览FollowSymLinks 用连接浏览
AllowOverride None                               #设置为 none,忽略.htaccess
</Directory>
LoadModule auth_basic_module modules/mod_auth_basic.so         #载入的库,模块
 
……….
Include conf.d/*.conf                              #conf.d 里面的 conf 文件也属有效配置文件
User apache#apache                              #运行以哪个身份运行
Group apache#apache                           #运行以哪个组的身份运行
ServerAdmin root@localhost                 #管理员邮箱
DocumentRoot “/var/www/html”          #默认的主目录,如果改动要改动两处,Directory
<Directory “/var/www/html”> Options Indexes FollowSymLinks AllowOverride None
Order allow,deny                                    #这里默认后者生效,也就是 deny 生效
Allow from all                                         #这里允许所有
</Directory>
LogLevel warn                                        #日志等级
DirectoryIndex index.html index.html.var          #首页
AccessFileName .htaccess                      #access 文件名
AddDefaultCharset UTF-8                      #支持的语言,默认编码
 
5.举个例子:
部门内部搭建一台WEB服务器,采用的IP地址和端口为192.168.1.13:80,首页采用index.html文件。管理员E-mail地址为 admin@hello2099.com,网页的编码类型采用UTF-8,所有网站资源都存放在/var/www/html目录下,并将Apache的配置文件根目录设置为/etc/httpd目录。
 
a.备份配置文件:
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup
 
b.修改配置文件:
vim /etc/httpd/conf/httpd.conf
 
设置Apache 的根目录为/etc/httpd
设置httpd 监听端口80
设置管理员E-mail地址为admin@hello2099.com
设置WEB 服务器的主机名和监听端口为192.168.1.13:80
设置Apache 文档目录为/var/www/html
设置主页文件为 index.html
设置服务器的默认编码为UTF-8
 
ServerRoot “/etc/httpd”  
Listen 80   
ServerAdmin admin@hello2099.com
ServerName 192.168.1.13:80
DocumentRoot “/var/www/html” 
Options Indexes FollowSymLinks
DirectoryIndex index.html index.php
AddDefaultCharset UTF-8
 
6.重启apache服务
service httpd restart
 
7.通过浏览器访问:192.168.1.13
 
8.Apache服务初步搭建完成。
 

 

赞(0)
可附来源转载:一只北极熊 » 使用Apache搭建Web网站服务器

富强、民主、文明、和谐、自由、平等、公正、法治、爱国、敬业、诚信、友善