什么是 Web 服务器(server)

前端开发人员应该对 Web 开发中的基本概念有一些了解,请简述
1. 什么是 Web 服务器
2. Web 服务器能做什么

首先我们来了解什么是服务器(server)

一般来说,server 有两重意思

  1. 有时候 server 表示硬件,也就是一台机器。它还有另一个名字:「主机」。
  2. 更多时候,server 表示软件程序,这种程序主要用来对外提供某些服务,比如邮件服务、FTP 服务、数据库服务、网页服务等。

作为开发者,我们说 server 的时候,一般指的后者,也就是一个 24 小时运行的软件程序。

一台主机上面可以运行多个这样的程序。

什么是 Web Server?

顾名思义,Web Server 就是提供 Web 服务的 Server。

比如我们访问 http://baidu.com,其实就是在使用百度的 Server 提供的服务。

一般来说, Web Server 对外提供的是 HTTP 服务(也可以是其他服务),这就是为什么我们的网址都以「http://」开头。

如何提供 HTTP 服务?

下面是有 Node.js 写的一个最简单的 HTTP server

// 文件名 index.js
// 使用 node index.js 可运行本程序

var http = require('http')

var server = http.createServer( function (request, response){
    response.end('这是页面内容,你请求的路径是:' + request.url)
})

server.listen(8080, function(){
    console.log("正在监听 %s 端口", 8080);
});

你不用看懂这段程序,你只需要知道两件事情:

  1. 这段程序监听了当前机器的 8080 端口。
  2. 一旦外部访问当前机器的 8080 端口,这段程序就会返回一段文字。

这就是一个最简单的 HTTP server。

分类

提供 HTTP 服务的 server 分为两类。

  • 静态文件服务器

这种服务器简单地根据访问路径,返回对应的文件。
比如用户访问 http://123.123.123.123:8080/a/b/c/d.html,那么这种服务器就会在网站根目录找到 a/b/c/d.html 文件,原样返回给用户。

  • 动态内容服务器

这种服务器返回的内容一般不是文件,而是动态生成的字符串(比如从数据库中获取的字符串)。
比如用户访问 http://weibo.com/home,那么这种 weibo.com 的服务器则会返回当前用户最新的微博消息。显然每个用户得到的内容是不一样的。

以上,就是 Web 服务器的简单描述。

作者:方应杭,想学前端?进群

30 thoughts on “什么是 Web 服务器(server)”

  1. I like the helpful info you provide to your articles. I will bookmark your blog and test once more right here frequently.
    I’m quite sure I’ll be told many new stuff right here!
    Good luck for the next!

  2. When some one searches for his necessary thing, thus
    he/she desires to be available that in detail, therefore
    that thing is maintained over here.

  3. Aw, this was an incredibly good post. Taking the time
    and actual effort to make a really good article… but what
    can I say… I put things off a whole lot and don’t seem
    to get nearly anything done.

  4. Please let me know if you’re looking for a author for your weblog.
    You have some really good articles and I think I would be a good asset.

    If you ever want to take some of the load off, I’d love to write some articles for your blog in exchange for a link
    back to mine. Please shoot me an email if interested. Regards!

  5. My programmer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the expenses. But
    he’s tryiong none the less. I’ve been using WordPress on numerous websites for about a year
    and am nervous about switching to another platform. I have heard fantastic things about blogengine.net.
    Is there a way I can import all my wordpress content into it?

    Any help would be really appreciated!

  6. It’s truly very difficult in this busy life to listen news on Television,
    therefore I simply use the web for that purpose, and obtain the most
    up-to-date information.

  7. You should participate in a contest for probably the greatest blogs on the web. I’ll recommend this web site!

  8. I wanted to develop a note in order to say thanks to you for all of the unique tips you are writing here. My particularly long internet investigation has now been honored with awesome strategies to talk about with my partners. I ‘d tell you that we visitors are unquestionably fortunate to dwell in a fine network with very many perfect people with insightful advice. I feel very blessed to have used your website page and look forward to really more entertaining times reading here. Thanks a lot once again for all the details.

  9. I definitely wanted to type a word to express gratitude to you for some of the unique instructions you are sharing on this website. My extended internet research has at the end been honored with reliable suggestions to share with my colleagues. I ‘d claim that many of us readers actually are truly endowed to live in a fine place with so many lovely individuals with very helpful methods. I feel quite fortunate to have discovered the webpage and look forward to so many more excellent times reading here. Thank you once more for a lot of things.

  10. I have to show my admiration for your generosity supporting persons that have the need for help with the niche. Your very own commitment to passing the solution along turned out to be extraordinarily significant and have usually helped employees like me to achieve their goals. Your new important recommendations signifies a lot to me and a whole lot more to my colleagues. Many thanks; from everyone of us.

  11. I wanted to make a quick note to be able to express gratitude to you for those precious pointers you are showing on this site. My time intensive internet research has at the end of the day been compensated with beneficial points to write about with my colleagues. I ‘d point out that we website visitors are really endowed to live in a perfect network with many awesome people with useful strategies. I feel quite happy to have seen your website and look forward to so many more entertaining moments reading here. Thank you again for a lot of things.

  12. I precisely wanted to say thanks once more. I’m not certain the things that I might have followed in the absence of these methods documented by you relating to this area of interest. It previously was the depressing circumstance in my view, however , understanding a new skilled way you handled the issue made me to jump over gladness. I’m happy for your service and even wish you really know what an amazing job you have been providing teaching some other people through the use of your web page. I am sure you have never met any of us.

  13. Thank you so much for giving everyone such a splendid chance to read in detail from this website. It’s usually so terrific and stuffed with a great time for me personally and my office peers to visit your blog a minimum of thrice weekly to see the latest guides you have. And definitely, I’m so certainly fascinated concerning the splendid opinions served by you. Some two areas in this article are really the very best we’ve had.

  14. Thank you a lot for giving everyone an exceptionally nice possiblity to read critical reviews from here. It’s always very fantastic and jam-packed with a great time for me personally and my office friends to search your web site on the least thrice in a week to study the latest guidance you will have. And indeed, I am just actually contented concerning the good opinions served by you. Selected two areas in this article are particularly the finest I have ever had.

  15. you are actually a excellent webmaster. The web site loading
    speed is incredible. It sort of feels that you are doing any distinctive trick.
    Furthermore, The contents are masterpiece.
    you have performed a wonderful task in this topic!

    31muvXS cheap flights

  16. I simply wanted to thank you so much once again. I do not know the things I would’ve worked on in the absence of the type of ways shared by you on this theme. It had been a real depressing situation for me, nevertheless viewing the very professional form you dealt with it made me to weep with gladness. Now i’m grateful for this guidance and then believe you know what an amazing job you are always putting in instructing other individuals by way of your webblog. I am certain you’ve never got to know all of us.

  17. What’s up to every body, it’s my first pay a quick visit of this blog; this website consists of amazing and actually fine information in favor of readers.

  18. I wanted to jot down a quick remark to say thanks to you for those wonderful hints you are giving on this website. My considerable internet lookup has at the end of the day been rewarded with high-quality facts and strategies to go over with my company. I ‘d repeat that we site visitors actually are quite endowed to dwell in a magnificent place with so many brilliant people with insightful solutions. I feel somewhat happy to have seen your site and look forward to many more pleasurable minutes reading here. Thank you again for all the details.

  19. I needed to put you one bit of note to say thanks a lot over again for these incredible information you have featured on this site. It’s certainly surprisingly open-handed of you to supply openly exactly what a number of people might have offered for sale for an e-book to help make some money on their own, most notably since you could possibly have done it in case you desired. The strategies as well served to be the fantastic way to realize that most people have the same dream similar to my own to find out lots more when it comes to this condition. I think there are many more enjoyable moments ahead for individuals that see your website.

  20. There are some fascinating deadlines on this article however I don抰 know if I see all of them heart to heart. There’s some validity but I will take hold opinion till I look into it further. Good article , thanks and we wish more! Added to FeedBurner as properly

  21. I discovered your weblog site on google and examine a number of of your early posts. Proceed to keep up the superb operate. I simply additional up your RSS feed to my MSN News Reader. In search of forward to reading more from you in a while!?

发表评论

电子邮件地址不会被公开。