Web Server for Beginners Build--iis (reprint)

Source: Internet
Author: User

First, the construction of IIS server

IIS full name Internet Information Service, Chinese name: Internet Information Services, dedicated to the Microsoft operating system platform, compatible with Microsoft's various web technologies, In particular, ASP. NET (in fact, can also run on IIS), in addition, IIS also support CGI,IIS7 later version of fast-cgi support better, so PHP 5.3 can use fast-cgi and Zend to optimize performance on IIS, Of course, early ASP is also supported, JSP support is relatively troublesome, and performance is not good, so basically no one to take IIS run JSP.

Now, IIS8 has been accompanied by the release of Windows Server R2 and Windows 8.1 in the latest version of Windows, so this article does not take IIS7 previous Antique said, IIS7 later version, the change is very small, should be in the optimization of performance, Adds stability and adds new mime to some miscellaneous on-the-handle.

Okay, now let's get started!

The basic steps are as follows:

Enable features, set up Web site paths and ports, set permissions, Settings Miscellaneous, official release

1. Enable Features:

First, let's take the Windows desktop System example and go to the Windows Control Panel,

(Windows Desktop Edition Control Panel)

Go to Programs, then click Turn Windows features on or off, and then you'll see the option to find Internet Information Services (in Windows 7 for Internet Information Service, below),

(Windows features for Desktop edition)

Tick on the option box before Internet Information Services, you will find that some of the content is block-type, meaning that it is not fully enabled, it is recommended to follow the image on the "Application development features" in all the contents of the check, Otherwise, IIS can only hang HTML static Web pages later. Tick completion, such as the need for other functions, such as ODBC log, dynamic content compression, HTTP redirection and other functions, can also be checked again, of course, now do not check the next add also no problem.

(Shut down Windows firewall)

When finished, click OK, Windows automatically installs IIS features, after the installation is complete, it is recommended in "system and security", completely shut down the firewall, to ensure that the other IIS port can be accessed, in IE or other browser, open http://localhost, the following interface appears, It means that the building is successful

(IIS8 Welcome Interface)

Next, let's take a look at the IIS build process on Windows Server R2

First, open Server Manager, and in the upper-right corner, find "Manage", "Add roles and Features",

(Add roles and features to Windows Server R2 Server Manager)

Next, click "Next" until the "server role" item and find the "Web Server (IIS)" Item in the list on the right.

(Windows server R2 add server role)

After you successfully add a role, you will be prompted to select the features you want, similar to the previous Windows desktop version, choose your desired features, and we recommend that you check all the options in application development! If you are using it as a real server, it is best to fully align the functionality to save the configuration again. After checking, the "next step" waits for the installation to complete.

(Windows 7 and Windows Server R2 's configuration is similar to the corresponding desktop and server editions, you can refer to the configuration described above)

After installation, view the Windows service and discover a service called "World Wide Web Publishing Service", which is used to start and manage IIS processes, to automatically run when Windows starts up, Without requiring a single user to log in.

(Services for IIS)

2. Set the site path and port

Although the server function is enabled, although we can access it over the LAN via IP address or localhost, we are only looking at the example Microsoft gave us, we need to have IIS present our own Web site, and we need to put the web-related files, such as: ASPX, HTML, DLLs, and so on, here we demonstrate how to deploy a real dynamic site using the simplest form of webform in ASP.

First, assuming that our site has been fully developed in VS, the site base directory file is as follows:

(a basic WebForm website)

Note in advance: This site is a basic web API, based on the parameter ID (get or post submission), the data from the database to retrieve the corresponding ID, when the ID is 0 or cannot be converted to int type data, return all data, out of range return empty data.

If you run or debug directly, you will see the following screen, where the browser address is localhost+ a random port number, which is the VS will hang the site on its own IIS Express, but IIS Express only allows local debugging to use, If you test on LAN or turn off Debug vs, you will find that the site cannot be accessed.

(IIS Express Show results)

So, we can now have two ways to organize the files needed for the site, the first is to manually copy, the second is to use vs automatic packaging. If not the site is particularly large, the file is very much, or recommend that you copy. , open the project's source folder, we will see many files, there are. cs,. vscxproj,. config, etc., where we need only the following types:

First, the Site view or page file, WebForm for ASPX,MVC for cshtml or aspx,webservice for ASMX, etc.

Second, the site's resource files, such as JS script, pictures, CSS files, etc.

Third, the dynamic link library of the site, that is, the entire Bin folder, and its DLL files

IV, Web site configuration file, Web. config

(Website source folder)

The rest of the files, no matter what suffix end, all can not, but do not delete, are your own efforts!

Copy these files to the place where you need to hang the site, if the server system, as long as not the system directory, you can put any, if it is the desktop version of the system, do not put on the desktop, the system directory on the line, recommended in the following several paths:

First, the IIS default path, C:\inetpub\wwwroot\

Second, other paths other than the C-drive, such as D:\xxx

Third, other read-write, script executable paths for non-network paths


Next, we'll make the site path settings in IIS. Open IIS and see the Web site item in the list on the left, which lists all the sites that are mounted on the native IIS server

(List of sites in IIS)

Now consider whether to hang the Web site on another TCP port on the local computer (default Web site is bound 80 port, you can hang your own web site on a port of 8080, etc.) or a Web site in a virtual directory under 80 ports, described here separately.

First of all, if we hang the site on port 8080, we need to create a new site in the "site", the approximate operation is: Right-click "website", "Add Site", enter information, click "OK", where "site name" is filled in, "physical path" Choose to put the site-related files directory path, the remaining port to 8080 or other unoccupied ports, click OK, access to http://localhost:8080/or IP address to see their website,

(Add a new site)

Second, we take a look at the way the virtual path is added, the so-called virtual path, is similar to http://www.xiyoumobile.com/admin/and other access methods, seemingly visited another folder in the site, actually visited another site, in IIS can choose " Add virtual directory "and" Add Application "two methods implemented, personally recommend the latter, because you do not have to consider the location of the. dll file because of creating a new virtual directory. Action: For the site to add the virtual directory, right-click Add Application, fill in the alias and path, you can enter the Web site in the browser to access the site, where "alias" please fill in the name of the virtual directory you want to access, such as http:// Www.xiyoumobile.com/admin/, the alias should be filled with "admin", and "path" in accordance with the method of new Web site can be filled,

(Add virtual directory)

3. Set permissions

Windows NT System for security reasons, set up the user groups and Permissions division, especially in the ordinary desktop version or the family version of the system is more obvious, the server is often given the highest authority on the administrator, there are children shoes said, according to the above method, the completion of the server after the , the Web page can open, but will error, 500 or 401, and so on, basically because of the permissions, if 401 is what permissions are not, 500 is likely to write the local database, the file is forbidden to write the server error caused by, so, Please carefully check the permissions of the site directory for the children's shoes is enough.

How to check it, very simple, open IIS, select a Web site or virtual directory in the list on the left, and then, in the Action column on the right, select Edit permissions, security,

(Edit Site Directory permissions in IIS)

Here you can see that my Site Directory permissions include "Everyone", "Authenticated Users", "SYSTEM", "Administrators" and several other user groups or user names, and allow the "Everyone" user group to read and execute , listed and so on, so the site's script, content is to allow anyone to access or say get, some children's shoes have not set permissions on the hard disk, there may be no everyone's this permission, so it is possible to access the following conditions

(Access failed because of insufficient permissions)

In this case, you can add the Everyone or IIS_IUSRS access right in the "Security" (Site Directory folder) just now, and if you need a file upload, you can make a folder readable and writable, as long as you tick the required permissions.

(Set permissions for IIS_IUSRS)

4. Setting up Miscellaneous

Children's shoes should be urgent, this site should be able to calculate the official release, don't worry, there is something to say!!

First, the default document

Some children's shoes said, installation of the method you said is configured, how to open or error ah, like the following error:

HTTP Error 403.14-forbidden
The WEB server is configured to not list the contents of this directory.

(the website did not find the default document error)

But you will find that if you hit http://localhost:8080/Default.aspx and you can access it because the default document for IIS is the following: Default.htm, Default.asp, Index.htm, Index.html, Iisstart.htm, Default.aspx (here is a note, because Windows system is not case-sensitive on the path, so the site published on IIS is also case-insensitive), if your home file is not in the above file, the document name is not lost, the default is inaccessible (I deliberately deleted the Default.aspx), so , for this scenario, set the default document yourself, as follows (suppose you want to hang a PHP site):

(add default document)

After adding the default document, directly hit the domain name or IP and port number can be method default page!

Second, the database connection string

Some children's shoes because SQL Server uses Windows authentication at native testing, the connection string that is automatically generated to Web. config is shown below

[HTML]View PlainCopy
    1. <add name= "exampleconnectionstring" connectionstring= "Data source=.\sqlexpress;initial catalog=example;integrated security=true "
    2. providername="System.Data.SqlClient" />

If you use this connection string directly on a Web site, you will find a Web page hint:

Unable to open the database "Example" requested by the login. Login failed.

The user ' IIS Apppool\defaultapppool ' logon failed.

(Database exception)

Therefore, it is important to note that before you mount a Web site to a real IIS server, you will modify the string in Web. config to ensure that the database uses SQL Server authentication, and that if the database is installed natively, the data source is best set to localhost. 1433, as shown in the following code:

[HTML]View PlainCopy
    1. <add name= "ConnectionString" connectionstring= "Data source=localhost,1433;initial catalog=Example; User
    2. id=sa; password=123456 "Providername="System.Data.SqlClient "/>


Third, the. NET Framework Version

In particular, in Windows 7, the. NET Framework 3.5 is supported by default and can be caused if the. NET Framework 4 and IIS are installed in different order. NET does not have an issue registering in IIS, so it is recommended that you run CMD as an administrator before you install the. NET Framework, or IIS first, and then enter X:windows\microsoft.net\framework\ v4.0.30319 (64-bit: X:windows\microsoft.net\framework64\v4.0.30319,x represents the system installation disk, such as C), and then executes the command aspnet_regiis.exe-i, which ensures that. NET4 is registered with Iis,iis in order to run normally. NET4 version of the program.

Furthermore, if the application development is selected. NET4, while the Web application chooses. NET2, too.

Both of these belong to the running framework exception, must be configured correctly, otherwise it will be an error!

(Select the correct application pool)

Four, disable debug information

Debugging information is generally useful in local development, after the official release if visitors see, will also expose some of the site information, while it appears that developers are very amateur, so after the formal deployment, close debugging information, the specific operation is as follows:

Modify the Web. config to modify the following content

[HTML]View PlainCopy
    1. <system.web>
    2. <compilation debug="true" targetframework="4.0" />
    3. </system.web>

After modification

[HTML]View PlainCopy
    1. <system.web>
    2. <compilation debug="false" targetframework="4.0" />
    3. </system.web>

This turns off debugging information when remote access is turned on

Five, add MIME type

If you need to have a Web site provide some new file access services, you must add some files in IIS suffix name and MIME type, especially IIS7, the default does not have. mp4 format file support, if you do not add MIME type, HTML5 is not easy to implement, there are other files, such as APK, IPA and other installation packages, due to infrequently used, in IIS also need to manually add, if not added, will be reported "404 Not Found" error, add the method as follows:

(Add MIME type)

Six, other settings

Other settings include access control, IP address filtering, reverse proxy, SSL, log, CGI, and so on, which are configured according to individual needs, and are not very difficult unless you are running Java on IIS. On the reverse proxy of IIS, children's shoes can poke my other blog: "Direction agent on IIS", I will continue to write a tutorial for novice Web server, covering Nginx, Apache and PHP on IIS and so on, thank you for your attention!

Reprinted from: http://blog.csdn.net/yuanguozhengjust/article/details/25747729

Web Server for Beginners Build--iis (reprint)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.