当前位置:网站首页>自己动手搭建一个简单的网站
自己动手搭建一个简单的网站
2022-06-29 03:47:00 【talk_8】
我准备搭建一个属于自己的网站,一方面是了解建站的知识,另一个方面是为了测试Http请求相关的内容。
建站资料
下面是建站需要的资料:
- 服务器:也就是高级一点的电脑,它主要用来存放网页数据;
- web服务器:就是一个软件,常用的有Apache和Nginx;
- 网页程序:就是网站显示的内容,需要自己动手来编写;
建站步骤
下面是具体的实现步骤,请大家参考:
- 在Win7上安装一个虚拟机,我安装的是
VirtualBox;然后创建个虚拟机来充当服务器; - 在虚拟机中安装Linux系统,我安装是的Mint,如果有不会安装的,可以看我以前的博客;
- 在Linunx系统中安装Web服务器,我安装的是
Nginx,简单起见,我直接使用命令进行安装,具体如下:
sudo apt install nginx-full
演示网站
此时,一个简单的网站已经创建好了,接下来验证一下创建的网站是否可用。首先打开Mint中的浏览器(默认是Firefox),在浏览器的地址栏中输入localhost(或者127.0.0.1),这时就会显示一个网站页面,具体如下图所示:

这是Nginx服务器默认的网站页面,如果不能显示此页面,说明Nginx安装失败。安装Nginx时也可以使用编译源码的方式来安装,其优点是可以配置各种需求,缺点是安装时间较长而且相对复杂一些。
除了在本机(虚拟机中的服务器)上访问网站外,还可以在Win7(主机)上访问网站,首先打开Win7中的浏览器,接着在浏览器中输入虚拟机的IP地址,此时会显示上面图片中的页面。这种访问方式和真实场景类似:虚拟机中的服务器相当于真实场景中的服务器,Win7相当于我们日常使用的电脑。
使用这种方式时还需要对虚拟机的网络做设置,不然无法在Win7(主机)上访问服务器(虚拟机中的Nginx服务器),具体的设置如下:
打开虚拟机的设置菜单,选择网络,在弹出窗口中选择网卡2,将其设置为Host-Only网络,具体如下图所示:

一个简单的网站就这样搭建好了,希望大家都自己动手去实践,这样可以掌握其背后的原理。
建站原理
在实际项目中,搭建网站也是同样的原理,不过服务器是真实的电脑不是虚拟机,服务器上运行的操作系统可能是Linux或者Windows Server.服务器上运行的Web服务器可能是Apache或者Nginx.我们为了简单起见使用的是Nginx默认的Web页面,在实际场景中需要自己创建Web页面,这就是我们通常说的前端。我们访问网络时使用的服务器的IP地址,在实际场景中是不可以的,因此我们还需要通过DNS服务器把IP地址转换成域名地址,也就是我们常用的www.xxx.com。我们在这里只是演示如何创建一个简单的网站 ,因此没有使用DNS服务器解析域名。
边栏推荐
- Data collection and management [12]
- Whose encryption key is written in the code? (that's you)
- [ruoyi] ztree initialization
- 【C语言】详解线程回收函数 pthread_join
- Inventory deduction based on redis
- How to back up all data on Apple mobile phone in 2 steps (free)
- 人大金仓(KingBase)导出表结构
- 百度智能云服务网格产品CSM发布 | 火热公测中
- Data statistical analysis (SPSS) [3]
- VG4131SxxxN0S1无线模块硬件规格书
猜你喜欢

leetcode - 295. Median data flow

基于可变参模板实现的线程池

leetcode - 295. 数据流的中位数

Seekbar custom pictures are not displayed completely up, down, left, right / bitmaptodrawable / bitmaptodrawable inter rotation / paddingstart/paddingend /thumboffset

Do you feel confused when you study at three in the morning?

【TcaplusDB知识库】批量复制游戏区
![[tcaplusdb knowledge base] Introduction to tcaplusdb tcaplusadmin tool](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[tcaplusdb knowledge base] Introduction to tcaplusdb tcaplusadmin tool
![[Brillouin phenomenon] Study on simultaneous measurement system of Brillouin temperature and strain distribution in optical fiber](/img/92/57792ef733964230d36e0b9bb218b4.png)
[Brillouin phenomenon] Study on simultaneous measurement system of Brillouin temperature and strain distribution in optical fiber

Vg4131sxxxn0s1 wireless module hardware specification

科技雲報道:混合辦公的B面:安全與效率如何兼得?
随机推荐
Inventory deduction based on redis
做 SQL 性能优化真是让人干瞪眼
MySQL Varcahr to int
Preliminary construction of SSM project environment
Kingbase export table structure
Web crawler knowledge day04
Data statistical analysis (SPSS) [6]
增额终身寿险下架了吗?现在还有哪些增额终身寿险产品?
【TcaplusDB知识库】TcaplusDB数据导入介绍
Data statistical analysis (SPSS) [4]
Source code analysis of go redsync distributed lock
Seekbar custom pictures are not displayed completely up, down, left, right / bitmaptodrawable / bitmaptodrawable inter rotation / paddingstart/paddingend /thumboffset
欧拉开源社区第二届理事会第二次会议召开,新华三、超聚变和龙芯中科成为理事会成员单位
Do you feel confused when you study at three in the morning?
Microsecond TCP timestamp
科技云报道:混合办公的B面:安全与效率如何兼得?
[Ubuntu] [MySQL] Ubuntu installs mysql, but the compilation error is mysql h: No such file or directory
【C语言】开启一个线程
Data statistical analysis (SPSS) [8]
Open source demo| you draw and I guess -- make your life more interesting