Linux系统应用:Web服务器(Apache2)的简单配置

常用的Web服务器有Apache、IIS、 Tomcat 、Nginx、Lighttpd、IBM Websphere等,其中应用最广泛的是Linux下的Apache(Apache也应用在Windows平台下),是世界使用排名第一的Web服务器软件;它可运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。而Windows平台下最常用的Web服务器是IIS。

防火墙配置命令ufw

安装ufw

apt-get install ufw

常用命令

ufw enable			开启防火墙
ufw disable			关闭防火墙
ufw status			查看防火墙状态
ufw allow [port]	允许端口port被外部访问
ufw deny [port]		拒绝端口port被外部访问

安装Apache

命令行安装

apt-get install apache2

查看是否安装成功

dpkg -l | grep apache

访问Apache服务器:

(1)在终端执行ifconfig命令查看Linux系统的IP地址(如192.168.0.1),并打开浏览器输入localhost或者http://192.168.0.1查看Apache服务器是否可以访问

(2)若在外部访问(如Windows系统),需要在终端将防火墙关闭(或者允许Apache的默认端口80被外部访问),在浏览器输入Linux系统的IP地址,查看Apache服务器是否可以被访问

配置Apache

(一)默认网站首页存放主目录路径

配置文件路径:/etc/apache2/sites-available/000-default.conf

参数:DocumentRoot [path]

# 000-default.conf

ServerAdmin webmaster@localhost
DocumentRoot /home/serein/Desktop/Apache

同时要在/etc/apache2/apache2.conf中将该目录路径授权,否则访问时会出现没有权限的错误。

# apache2.conf

<Directory [path]>
	AllowOverride None
	Require all granted
</Directory>

(二)默认网站首页

配置文件路径:/etc/apache2/mods-available/dir.conf

参数:DirectoryIndex [file1] [file2] …

可以对应多个文件,若前面的网页找不到则往后查找

# dir.conf

<IfModule mod_dir.c>
	DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

(三)端口号

配置文件路径:/etc/apache2/ports.conf

参数:Listen [port]

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80

配置文件路径:/etc/apache2/site-available/000-default.conf

参数:<VirtualHost *:[port]>

# 000-default.conf

<VirtualHost *:777>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	

两个配置文件都要修改,监听端口号才会生效!

(四)虚拟目录

配置文件路径:/etc/apache2/apache2.conf

参数:Alias [虚拟目录] [物理目录]

虚拟目录的作用是隐藏真实的物理路径,输入虚拟路径即可访问对应物理路径的内容

# apache2.conf

# 虚拟目录
Alias /mytest /home/test_index

# 对物理路径授权
<Directory /home/test_index>
	AllowOverride None
	Require all granted
</Directory>

查看自定义配置后的的服务器首页

1.使用ufw命令允许你配置的监听端口号被外部访问(或直接关闭防火墙)。

2.重启Apache服务。

service apache2 restart

3.在Windows系统或其他主机的浏览器中输入Linux系统的IP地址及你配置的端口号(默认为80)。
在这里插入图片描述

  • 0
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晚风也很浪漫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值