华为云:搭建网页服务器

来自CloudWiki
跳转至: 导航搜索

远程登录服务器

使用CloudShell登录

如果忘记密码,可以重置实例密码

软件安装

安装apache软件:

yum install httpd -y

启动apache软件:

service httpd restart

安全设置

关闭防护墙和Selinux

在远程命令行终端中远程执行linux命令:

关闭防火墙:

systemctl stop firewalld

关闭selinux:

setenforce 0

setenforce: SELinux is disabled




验证

刚才我们安装了apache服务器,

并关闭了防火墙,现在验证一下在公网上是否能够访问。

浏览器输入云主机 IP:

Cloud20101706.png

这个页面为apache默认页面。

我们可以上传自己的页面来替代这个页面。

如果打不开,请检查云服务器的安全组是否打开80端口。

编写网页

编程工具

这里我推荐微软家的 Visual Studio Code,和其他编辑器比中文系统默认安装好就是中文,而且功能丰富,是一个比较不错的代码编辑器。

下载地址:https://code.visualstudio.com/Download

网页编写

将以下代码在网页编辑器保存,另存为index.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
 
<h1>我的第一个标题</h1>
 
<p>我的第一个段落。</p>
 
</body>
</html>


菜鸟教程:https://www.runoob.com/

标题:https://www.runoob.com/html/html-headings.html

段落:https://www.runoob.com/html/html-paragraphs.html

链接:https://www.runoob.com/html/html-links.html

图像:https://www.runoob.com/html/html-images.html

表格:https://www.runoob.com/html/html-tables.html

上传文件

远程文件目录树 /var/www/html

https://edu.huaweicloud.com/certifications/2fa579f4a81d420a94ac6a7bd12fed08

上传文件后通过浏览器输入Ip进行访问,应该能看到你上传的网页。

如果出现403错误,可以在linux中输入 chmod -R 777 /var/www/html 命令更改文件权限