阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下Apache服务器配置

107次阅读
没有评论

共计 3558 个字符,预计需要花费 9 分钟才能阅读完成。

Linux 下 Apache 服务器配置
相关包:
httpd-2.2.3-29.e15.i386.rpm                 // 主程序包
httpd-devel-2.2.3-29.e15.i386.rpm        // 开发程序包
httpd-manual-2.2.3-29.e15.i386.rpm     // 手册文档
system-config-httpd-1.3.3.3-1.e15.noarch.rpm   // 配置工具
注:安装时会出现依赖包问题,可用 YUM 安装来解决
   启用时需要配置防火墙来放行
 
开机自动加载:
chkconfig –level 3 httpd on 
 
配置实例:
例 1:部门内搭建一台 WEB 服务器,采用的 IP 地址和端口为 192.168.0.3:80,首页采用 index.html 文件。管理员 E -mail 地址为 root@sales.com,网页的编码类型采用 GB2312,所有网站资源都存放在 /var/www/html 目录下,并将 Apache 的根目录设置为 /etc/httpd 目录。
编辑主配置文件 httpd.conf
vim /etc/httpd/conf/httpd.conf    // 编辑主配置文件
ServerRoot “/etc/httpd”             // 设置 Apache 的主目录
Timeout 120                             // 设置请求超时
Listen 80                                  // 设置监听端口
ServerAdmin root@sales.com          // 设置管理员邮箱
ServerName 192.168.0.3:80           // 设置主机或 IP
DocumentRoot “/var/www/html”      // 设置 Apache 文档目录
DirectoryIndex index.html               // 设置主页文件
AddDefaultCharset GB2312            // 设置网站编码
编辑主页文件用作测试:
cd /var/www/html
echo “This is web test sample.”>>index.html
chmod 705 index.html
重新加载服务:
service httpd restar
 
例 2:假设 Apache 服务器具有 192.168.0.2 和 19.16.0.3 两个地址,然后配置 Apache,把多个网站绑定在不同的 IP 地址上,访问服务器上不同的 IP 地址,就可以看到不同的网站。
(基于 IP)
mkdir /var/www/ip1   /var/www/ip2           // 创建两个主目录
编辑 httpd.conf 文件:
<Virtualhost 192.168.0.2>                      // 设置虚拟主机的 IP
   DocumentRoot /var/www/ip1                // 设置虚拟主机的主目录
   DirectoryIndex index.html                    // 设置主页文件
   ServerAdmin root@sales.com               // 设置管理员邮箱
   ErrorLog  logs/ip1-error_log                 // 设置错误日志的存放位置
   CustomLog  logs/ip1-access_log common       // 设置访问日志的存放位置
</Virtualhost>
<Virtualhost 192.168.0.3>                      // 设置相应的 IP
   DocumentRoot /var/www/ip2
   DirectoryIndex index.html
   ServerAdmin root@sales.com
   ErrorLog  logs/ip2-error_log
   CustomLog  logs/ip2-access_log common
</Virtualhost>
 
(基于域名)
mkdir /var/www/smile   /var/www/long         // 创建两个主目录
编辑 httpd.conf 文件:
<Virtualhost 192.168.0.3>                         // 设置虚拟主机的 IP
   DocumentRoot /var/www/smile                // 设置虚拟主机的主目录
   DirectoryIndex index.html                       // 设置主页文件
   ServerName www.smile.com                    // 设置虚拟主机完全域名
   ServerAdmin root@sales.com                  // 设置管理员邮箱
   ErrorLog  logs/smile-error_log                 // 设置错误日志的存放位置
   CustomLog  logs/smile-access_log common     // 设置访问日志的存放位置
</Virtualhost>
<Virtualhost 192.168.0.3>
   DocumentRoot /var/www/long
   DirectoryIndex index.html
   ServerName www.smile.com                     // 设置虚拟主机完全域名
   ServerAdmin root@sales.com
   ErrorLog  logs/long-error_log
   CustomLog  logs/long-access_log common
</Virtualhost>
 
(基于端口)
mkdir /var/www/port8080   /var/www/port8090        // 创建两个主目录
编辑 httpd.conf 文件:
Listen 8080
Listen 8090
<Virtualhost 192.168.0.3:8080>                            // 设置相应的端口
   DocumentRoot /var/www/port8080                     // 设置虚拟主机的主目录
   DirectoryIndex index.html                                  // 设置主页文件
   ServerAdmin root@sales.com                             // 设置管理员邮箱
   ErrorLog  logs/port8080-error_log                     // 设置错误日志的存放位置
   CustomLog  logs/port8080-access_log common  // 设置访问日志的存放位置
</Virtualhost>
<Virtualhost 192.168.0.3:8090>                          // 设置相应的端口
   DocumentRoot /var/www/port8090
   DirectoryIndex index.html
   ServerAdmin root@sales.com
   ErrorLog  logs/port8090-error_log
   CustomLog  logs/port8090-access_log common
</Virtualhost>

Ubuntu Server 14.04 安装 Web 服务器 (Linux+Apache+MySQL+PHP)  http://www.linuxidc.com/Linux/2015-06/119061.htm

Linux 下安装配置 PHP 环境 (Apache2)  http://www.linuxidc.com/Linux/2015-05/118062.htm

Linux 下 Apache 服务器配置  http://www.linuxidc.com/Linux/2016-06/132025.htm

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 5.9 下编译安装 LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm

RedHat 5.4 下 Web 服务器架构之源码构建 LAMP 环境及应用 PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm

Linux 下 Apache 虚拟主机的配置  http://www.linuxidc.com/Linux/2016-04/130381.htm

Apache 的详细介绍 :请点这里
Apache 的下载地址 :请点这里

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-10/136517.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计3558字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中