Ubuntu14.04 安装 Apache 服务器 实现浏览器访问文件

Apache

Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一

安装 appache-server

sudo apt-get install apache2

遇到如下错误

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package apache2

然后我尝试 apt-get update

moi@moi:~$ sudo apt-get update
Get:1 http://mirrors.aliyun.com quantal InRelease [2281 B]                 
Ign http://mirrors.aliyun.com quantal-updates InRelease                        
100% [1 InRelease gpgv 2281 B] [Connecting to mirrors.aliyun.com (180.163.155.1Splitting up /var/lib/apt/lists/partial/mirrors.aliyun.com_ubuntu_dists_quantal_IIgn http://mirrors.aliyun.com quantal InRelease                                
E: GPG error: http://mirrors.aliyun.com quantal InRelease: Clearsigned file isn't valid, got 'NODATA' (does the network require authentication?)
moi@moi:~$ 

结果发现是公司网络问题,导致工控机不能链接镜像。

sudo apt-get install apache2

修改配置文件 000-default.conf

sudo vi /etc/apache2/sites-available/000-default.conf 

此文件描述了网站的端口,路径等重要信息。
此处我们只修改了 网站的根目录,在/home/share 文件夹下

  <VirtualHost *:80> # 网站端口
         ServerAdmin webmaster@localhost
         DocumentRoot /home/share/    # 网站根目录
         ErrorLog ${APACHE_LOG_DIR}/error.log 文件存放处 # 错误日志
         CustomLog ${APACHE_LOG_DIR}/access.log combined  # 普通日志
  </VirtualHost>

修改 apache2.conf

sudo vi /etc/apache2/apache2.conf

此文件主要定义了网页路径的访问限制和要引入的库文件
其中需要修改一下网页根目录文件位置,与 000-default.conf文件保持一致

Servername 127.0.0.1
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>
<Directory /usr/share>  # 将/var/www/html 修改成目录
        AllowOverride None
        Require all granted
</Directory>

<Directory /home/share/>
        Options Indexes FollowSymLinks
#       AllowOverride None
        Require all granted
</Directory>

常用命令

启动

/etc/init.d/apache2 start
$ sudo /etc/init.d/apache2 start

重启apache服务

/etc/init.d/apache2 restart
$ sudo /etc/init.d/apache2 restart

停止apache服务

/etc/init.d/apache2 stop
$ sudo /etc/init.d/apache2 stop

大功告成

这里写图片描述

参考文献
https://www.cnblogs.com/cqmy/p/6208656.html Apache主配置文件httpd.conf 详解
https://blog.csdn.net/qq_32816985/article/details/58177175 apache2 启动、重启、停止方法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值