Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does the web server locate a file on server through URL?
    text
    copied!<p>Has anyone ever tried to implement a web server? Or know something about the underhood of a working web server program? I am wondering what happens exactly from when a URL is received by the web server to a file on the web server is located and sent back as response.</p> <p>Does the server just keep an internal table to remember the mapping between the URLs it supports and the corresponding local paths? Or is there anything more tricky?</p> <p>Thanks!</p> <h2>Update</h2> <p>Thanks for your replies. Here's my understanding for now.</p> <p>I checked with the Microsoft IIS (Internet Information Service), I noticed that IIS can host multiple sites, and foreach site IIS memorize its root path on the local file system. Different sites on the same host share the same host name or IP, and they are differentiated by separate ports. For example:</p> <pre><code>http://www.myServer.com:1111/folderA/pageA.htm </code></pre> <p>The web server will use <em>www.myServer.com:1111</em> part of the URL string to locate which path on its local file system will be used, and then in that local path, it searches for subfolder <em>folderA</em> and then the file <em>pageA.htm</em>.</p> <p>The web server <em>only</em> need to memorize the following mapping between 2 plain strings:</p> <pre><code>"http://www.myServer.com:1111/" &lt;---&gt; "D:\myWebRoot" </code></pre> <p>I don't know where this kind of mapping info is stored, maybe some config files for the Web Server Program in question. </p> <p>But the result of this mapping <strong>granularity</strong> is that we could only access content within that mapped local folder. We couldn't do arbitray mapping.</p> <h2>Update - 2 -</h2> <p>I found where the IIS keep the mapping, here's some quotes from applicationHost.config:</p> <pre><code>&lt;sites&gt; &lt;site name="Default Web Site" id="1" serverAutoStart="false"&gt; &lt;application path="/"&gt; &lt;virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" /&gt; &lt;/application&gt; &lt;bindings&gt; &lt;binding protocol="http" bindingInformation="*:80:" /&gt; &lt;binding protocol="net.tcp" bindingInformation="808:*" /&gt; &lt;binding protocol="net.pipe" bindingInformation="*" /&gt; &lt;binding protocol="net.msmq" bindingInformation="localhost" /&gt; &lt;binding protocol="msmq.formatname" bindingInformation="localhost" /&gt; &lt;/bindings&gt; &lt;/site&gt; &lt;site name="myIISService" id="2" serverAutoStart="true"&gt; &lt;application path="/" applicationPool="myIISService"&gt; &lt;virtualDirectory path="/" physicalPath="D:\MySites\MyIISService" /&gt; &lt;/application&gt; &lt;bindings&gt; &lt;binding protocol="http" bindingInformation="*:8022:" /&gt; &lt;/bindings&gt; &lt;/site&gt; &lt;siteDefaults&gt; &lt;logFile logFormat="W3C" directory="%SystemDrive%\inetpub\logs\LogFiles" /&gt; &lt;traceFailedRequestsLogging directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles" /&gt; &lt;/siteDefaults&gt; &lt;applicationDefaults applicationPool="DefaultAppPool" /&gt; &lt;virtualDirectoryDefaults allowSubDirConfig="true" /&gt; &lt;/sites&gt; </code></pre> <h2>Update - 3 -</h2> <p>After I read <a href="https://stackoverflow.com/users/448779/foo">foo</a>'s reply, my undersanding of a "server" is enlarged. I want to make some comment based on my recent learning of WCF. </p> <p>No matter what kind of server it is, we could always send messages to them by specifying the protocol, URL, port. For example:</p> <pre><code>[http://www.myserver.com:1111/]page.htm [net.tcp://www.myserver.com/]someService.svc/someMethod [net.msmq://www.myserver.com/]someService.svc [net.pipe://localhost/] </code></pre> <p>After the messages arrives at the <strong>server program</strong> using the parts in square bracket of above URLs, the rest part of the url will send to the server program as input for further processing. And the following behaviour could be as simple as static content feeding or as complex as dynamic content generating.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload