# vi /etc/httpd/conf/httpd.conf
把以下虚拟机的配置加在 httpd.conf  文件末尾即可

NameVirtualHost *:80               //注意:这行默认是有#号的,记得要去掉

# # VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for all requests that do not

# match a ServerName or ServerAlias in any block.

# ServerAdmin admin@centoscn.com
<VirtualHost *:80>
    ServerAdmin  admin@centoscn.com
    DocumentRoot  /var/www/html/centos
    ServerName www.centoscn.com
    ServerAlias www.centoscn.com
    ErrorLog logs/centoscn.com-error_log
    CustomLog log/centoscn.com-access_log common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin  admin@gamekey.com.cn
    DocumentRoot /var/www/html/gamekey.com.cn
    ServerName www.gamekey.com.cn
    ServerAlias www.gamekey.com.cn
    ErrorLog logs/gamekey.com.cn-error_log
    CustomLog logs/gamekey.com.cn-access_log common
</VirtualHost>

1.Apache2 Web 服务器的安装

sudo apt install apache2 -y

当安装Apache2包之后,Apache2相关的服务是启用的,并在重启后自动运行。
在某些情况下如果你的Apache2服务器没有自动运行和启用,可以输入以下命令来启动它。

sudo systemctl start apache2.service
sudo systemctl enable apache2.service
sudo systemctl status apache2.service

如果开启了防火墙(ufw),可以使用下面的命令来解除Web服务器的端口(80和443)限制。

sudo ufw status
sudo ufw allow in 'Apache Full'

可以访问Web服务器,输入服务器IP地址或主机名(http://IP_Address_OR_Host_Name),顯示如下

/etc/httpd/conf/下有httpd.conf,httpd.conf.bak兩個文件,如果套用httpd.conf.bak文件,顯示如下

2.將網站文件傳到服務器
新的linux CentOS服务器,安装好php环境后,apache默认解析路径是/var/www/html,也可以用自己设置的目录路徑:

例:在根目录下新建/data/website文件夹用来存放项目,准备工作:

创建目录


mkdir data
cd data
mkdir website


操作步骤


vim /etc/httpd/conf/httpd.conf

DocumentRoot “/var/www/html” 改为DocumentRoot “/data/website”


 
 
 
 
 
 
 
 
 
 
<Directory “/var/www/html”> 改为<Directory “/data/website”>

apahce的默认路径就更改完成,重启Apache服务器

service httpd restart

访问localhost的时候,会发现访问拒绝,这是为什么呢?
因为/home/wwwroot/web1/htdocs的权限是750,apache这个用户没有权限访问,需要更改权限

chmod -R 755 /data/website

再去访问,运行了(apache的用户:apache 运行apache的组:apache)
上傳網站文件到/data/website/目录下即可.

顺便说一点,防止网站乱码请将/etc/httpd/conf/httpd.conf中AddDefaultCharset UTF-8 改为 AddDefaultCharset OFF

3.Apache配置多网站多域名

vi /etc/httpd/conf/httpd.conf
    把虚拟机的配置加在 httpd.conf文件末尾即可

NameVirtualHost *:80              
    # VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for all requests that do not

# match a ServerName or ServerAlias in any block.

范例:    绑定两个网站

<VirtualHost *:80>

ServerAdmin  admin@centoscn.com

DocumentRoot  /data/website/centos

ServerName www.centoscn.com

ServerAlias www.centoscn.com

ErrorLog logs/centoscn.com-error_log

CustomLog log/centoscn.com-access_log common

</VirtualHost>

<VirtualHost *:80>

ServerAdmin  admin@gamekey.com.cn

DocumentRoot /data/website/gamekey.com.cn

ServerName www.gamekey.com.cn

ServerAlias www.gamekey.com.cn

ErrorLog logs/gamekey.com.cn-error_log

CustomLog logs/gamekey.com.cn-access_log common

</VirtualHost>

注:配置虚拟主机的时候,第一个虚拟主机是默认的,你需要留着,配置自己的虚拟主机,从第二个开始配置,也就是第二段 <VirtualHost> 代码。

centos5.5 Apache2 Web 服务器的安装的更多相关文章

  1. Apache2 Web 服务器

    Apache2 Web 服务器的安装 sudo apt install apache2 -y 当安装Apache2包之后,Apache2相关的服务是启用的,并在重启后自动运行.在某些情况下如果你的Ap ...

  2. Android手机用KSWEB搭建Web服务器成功安装WordPress

    之前部落分享的几个免费Web服务器软件都是用来安装在本地电脑上,搭建Apache.PhpMyAdmin.MySQL等网站运行环境,然后我们就可以在电脑上测试运行Wordpress.Discuz! 论坛 ...

  3. 淘宝开源Web服务器Tengine安装教程

    简介Tengine是由淘宝核心系统部基于Nginx开发的Web服务器,它在Nginx的基础上,针对大访问量网站的需求,添加了很多功能和特性.Tengine的性能和稳定性已经在大型的网站如淘宝网,淘宝商 ...

  4. nginx web服务器的安装使用

    nginx是一个web服务器(高性能web服务器),类似于apache服务器和iis服务器,由于nginx服务器具有轻量级高并发的特点,目前nginx的使用已经超越了apache. nginx介绍:n ...

  5. WEB服务器----Apache 安装配置

    1.官网下载需要的安装包(包括主安装包和依赖包的下载)可以直接使用Linux的wget进行下载: httpd安装包下载地址:http://mirrors.hust.edu.cn/apache//htt ...

  6. 如何在Ubuntu 16.04上安装Apache Web服务器

    转载自:https://www.howtoing.com/how-to-install-the-apache-web-server-on-ubuntu-16-04 介绍 Apache HTTP服务器是 ...

  7. 如何在Ubuntu 18.04上安装Apache Web服务器

    一. apt库安装 1.在终端输入更新检查命令,sudo apt-get update 2. 在更新完成后(如果不想检查更新,也可直接输入此步)输入:sudo apt-get install apac ...

  8. Java获取Web服务器文件

    Java获取Web服务器文件 如果获取的是服务器上某个目录下的有关文件,就相对比较容易,可以设定死绝对目录,但是如果不能设定死绝对目录,也不确定web服务器的安装目录,可以考虑如下两种方式: 方法一: ...

  9. SharePoint咨询师之路:设计之前的那些事四:负载均衡 - web服务器

     提示:本系列只是一个学习笔记系列,大部分内容都可以从微软官方网站找到,本人只是按照自己的学习路径来学习和呈现这些知识.有些内容是自己的经验和积累,如果有不当之处,请指正. 容量管理 规模 体系结构 ...

随机推荐

  1. redis 持久化与备份策略 【转载】

    本文转载自 http://blog.csdn.net/is_zhoufeng/article/details/10210353 持久化(persistence) 本文是 Redis 持久化文档 的中文 ...

  2. Sichuan State Programming Contest 2012 C。Counting Pair

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=118254#problem/C 其实这道题目不难...就是没有仔细分析... 我们可以发现 ...

  3. apt

    今天单元测试看到巨长字符串被加了很多引号,想起以前可以用跳脱符断行,试了不行,google说java7可以,我操. https://github.com/benelog/multiline/wiki/ ...

  4. RAS、AES、DES加密

    ---------------------------------------------------------------------------------------------------- ...

  5. CATranstion动画

    // 1.创建过度动画 CATransition *anima = [CATransition animation]; // 2.设置动画类型 anima.type = @"cube&quo ...

  6. json转义字符串

    json前台写数据 @RequestMapping("/addUserJson") public void addUserJson(User user,HttpServletReq ...

  7. html5 canvas 实现简单的画图

    今天早上看了一下 canvas 前端画图,数据可视化, 百度的 echart.js  , d3等 js 库都已经提供了强大的绘制各种图形的 API. 下面记录一下 有关canvas 绘图的基本知识: ...

  8. 如何用PC标签在列表页中调出文章内容 phpcms

    如何用PC标签在列表页中调出文章内容 phpcms v9 moreinfo=”"参数说明 {pc:content action="lists" catid="$ ...

  9. after和before的属性妙用

    ::after或::before设置它们的样式时有一个content这个属性这里可以写attr(data-label)其中data-label是标签上设置的data属性里的数据content:attr ...

  10. java SWT嵌入IE,SafeArray .

    java SWT嵌入IE,SafeArray );    // Create a by ref variant    Variant variantByRef = new Variant(pVaria ...