在树莓派上搭建web服务器——基于Apache

1,Apache简介:

Apache是世界使用排名第一的Web服务器软件它可以运行在几乎所有广泛使用的计算机

平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件。

详细介绍见:

百度百科—apache

维基百科—Apache HTTP Server

2,安装Apache到树莓派:

apt-get install apache2

提示Do you want to continue[Y/n] ? 的时候输入y,回车,等待安装完毕。

3,局域网访问测试:


在浏览器地址栏输入树莓派的IP地址,回车后你会看到下图所示的界面:



这就是默认的Apache Web Server的首页。
我们可以对这个页面文件进行修改,这个页面文件是/var/www/index.html,我用网页编辑工具对这个文件进行了修改,修改后的文件内容如下:
<p>
	<img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/13.gif" border="0" alt="" /><img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/18.gif" border="0" alt="" />阿覃是个逗逼!
</p>
<p>
	<img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/44.gif" border="0" alt="" /><img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/30.gif" border="0" alt="" />金刚是个逗逼!
</p>
<img src="tmp01.jpg" width="500" height="400"/>
<p>
	<img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/9.gif" border="0" alt="" /><img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/29.gif" border="0" alt="" /><img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/19.gif" border="0" alt="" /><img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/21.gif" border="0" alt="" /><img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/31.gif" border="0" alt="" /><img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/18.gif" border="0" alt="" /><img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/31.gif" border="0" alt="" /><img src="http://f.51240.com/file/zaixianwangyebianji/kindeditor-4.1.7/plugins/emoticons/images/4.gif" border="0" alt="" />
</p>

保存这个文件之后,然后再去访问,看到如下图所示的页面:



4,端口映射:

        现在我们搭建的网站只能在局域网内访问,我们可以通过设置路由器将树莓派的IP地址暴露给外网,使得外网也可以访问我们搭建的网站,同时,我们也可以申请一个花生壳账号,为我们做动态域名解析(免费的),这样我们就可以通过域名访问搭建在树莓派上的网站了。花生壳账号的注册流程就不列出了,大家自行百度解决。下面是路由器设置流程:

① 登陆你的路由器管理页面:


② 登陆你的花生壳账号:


③ 将树莓派IP暴露给外网:


点击“添加新条目”,填上树莓派的IP地址,然后再填一个端口号(默认的web服务器端口号是80,但是80端口往往都被运营商封了,所以我随便写了一个8899)

填写完后,点击“保存”。


5,外网访问测试:

在浏览器的地址栏输入你的花生壳免费域名:8899,回车,看到的页面跟之前在局域网看到的一致:


声明:

           本人系非计算机相关专业出身,以上博文中难免有诸多疏漏之处,希望大神勿喷!请多多指教!


猜你喜欢

转载自blog.csdn.net/u011708919/article/details/39430493