Web Server construction for beginners (1)-IIS Construction

Source: Internet
Author: User
Tags php website

Many children's shoes say they are engaged in mobile development. They want to build a simple Web API, but the server does not work, So Testing becomes a problem. Looking at the tutorials on the internet, I found it was a little difficult to understand, and most of them were transferred to one, so I simply wrote a few articles to explain how to build a simple Web server, quickly get started with children's shoes that do not involve much Web.

I plan to talk about several mainstream building methods on Windows or Linux, such as Apache, IIS, and Nginx.. NET. So, let's go to IIS first!


1. Set up an IIS server

IIS stands for Internet Information Service. Its Chinese name is Internet Information Service. It is dedicated to Microsoft operating system platform and is compatible with Microsoft's Web technologies, especially ASP. NET (in fact, it can run on IIS). In addition, IIS also supports CGI. Versions later than IIS7 have better support for Fast-CGI, therefore, PHP 5.3 can use Fast-CGI and Zend to optimize the performance on IIS. Of course, early ASP can also be supported. JSP support is relatively cumbersome and has poor performance, so basically no one uses IIS to run JSP.

Now, IIS8 has appeared in the latest Windows versions with the release of Windows Server 2012 R2 and Windows 8.1. Therefore, this article will not take IIS7 as an example, IIS7 and later versions, the variation is very small. It should be done on miscellaneous aspects such as optimizing performance, increasing stability, and adding new MIME.

Now let's get started!

The basic steps are as follows:

Enable the function-> set the website path and port-> Set permissions-> set miscellaneous-> officially released

1. Enable the function:

First, we take Windows desktop as an example to go to the "control panel" of Windows ",

(Windows desktop control panel)

Go to "program", click "enable or disable Windows", and then you can see the options and find Internet Information Services (Internet Information Services in Windows 7, the same below ),


(Windows functions of Windows desktop Edition)

Check the options box before Internet Information Services and you will find that some content is in the block type, which means that the functions are not fully enabled, we recommend that you check all the content in the "Application Development function" according to the introduction in the image. Otherwise, you can only choose static Web pages such as HTML after setting up IIS. If you need other functions, such as ODBC logs, dynamic content compression, and HTTP redirection, you can also select the option again after you select this option. Of course, if you do not select this option, you can add it again.


(Disable Windows Firewall)


After the installation is complete, click "OK" to automatically install IIS in Windows. After the installation is complete, we recommend that you completely disable the firewall in "system and security" to ensure that other IIS ports are accessible, in IE or other browsers, open http: // localhost and the following interface appears, indicating that the build is successful.


(IIS8 welcome page)

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

First, open "Server Manager" and choose "manage"> "add role and function" in the upper right corner ",


(Windows Server 2012 R2 Server Manager adds roles and functions)

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


(For Windows Server 2012 R2, add a Server role)

After successfully adding a role, you will be prompted to select the desired function. Similar to the previous introduction to Windows desktop edition, you are advised to select all the options in "Application Development! If it is used as a real server, it is best to configure all the functions without re-configuration. After the check box is selected, click "Next" and wait until the installation is complete.

(The configurations of Windows 7 and Windows Server 2008 R2 are similar to those of the corresponding desktop edition and Server Edition. Refer to the configuration described above)

After the installation is complete, check the Windows Service. You can find another Service named "World Wide Web Hing Service", which is used to start and manage the IIS process to ensure that Windows is started upon startup, it runs automatically without logging on to a user.


(IIS Service)


2. Set the website path and Port

Although the server function is enabled, although we can access the server through an IP address in the LAN or using localhost in the local machine, we only browsed the example provided by Microsoft, we need to let IIS display our own website. At this time, we need to include website-related files, such as aspx, html, and dll. Here, we use ASP. the simplest form of a single web page in. NET demonstrates how to deploy a real dynamic website.

First, assume that our website has been fully developed in VS. The basic directory file of the website is as follows:


(A Basic WebForm website)

Note one point in advance: This website is a basic Web API. Data of the corresponding id is retrieved from the database based on the parameter ID (submitted by GET or POST, if the id is 0 or cannot be converted to int type data, all data is returned. If the range is exceeded, NULL data is returned.

If you run or debug it directly, you will see the following figure. The browser address is localhost + a random port number. This is why VS hangs the website on its own IIS Express, however, IIS Express only allows local debugging. If you test on the LAN or disable VS debugging, you will find that the website cannot be accessed.


(IIS Express Display Results)

Therefore, we can now organize the files required by the website in two ways. The first is to manually copy the files, and the second is to use VS to automatically package the files. If the website is not very large and there are many files, we recommend that you copy the file yourself ., Open the source folder of the project and we will see many files, including. cs,. vscxproj,. config, etc. Among them, we only need the following types:

First, the view or page file of the website. The WebForm is aspx, the MVC is cshtml or aspx, And the WebService is asmx.

2. Website Resource files, such as js scripts, images, and css files

Third, the dynamic link library of the website, that is, the entire bin folder and Its dll files

Fourth, the website configuration file, Web. config


(Website source code folder)

All the remaining files, no matter what suffix they end with, can be left blank, but do not delete them, it is your own painstaking efforts!

Copy these files to the location where you need to link the website. If it is a server system, you can store the files as long as it is not a system directory. If it is a desktop system, do not place it on the desktop or system directory. We recommend that you put it in the following paths:

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

Second, other paths of non-C disks, such as D: \ xxx

Third, other non-Network-path read/write and script executable paths


Next, we need to set the website path in IIS. Open IIS and see "website" in the list on the left. All sites mounted on the local IIS server are listed.

(Website list in IIS)

Now you need to consider attaching a website to another TCP port on the local machine (Default Web Site is bound to port 80 by Default, and your website can be mounted to port 8080 and other ports, you can also mount the website to a virtual directory under port 80.

First, if we mount the website on port 8080, we need to create a new website on the website. The general operation is: right-click "website"-> "add Website"-> enter information-> click "OK", and fill in "website name" as needed, select the directory path where the website-related files are stored in the "physical path", and change the remaining port to 8080 or other unused ports. Click OK to access http: // localhost: 8080/or an IP address to view your website,


(Add a new website)

Next, let's look at how to add a virtual path. The so-called virtual path is similar. Specific Operation: Right-click the website to add a virtual directory-> "add application"-> Fill in "alias" and "path"-> OK, enter the website in the browser to access the website. For "alias", enter the name of the virtual directory to be accessed, such as "alias,


(Add a virtual directory)

3. Set permissions

For the sake of security, the Windows NT System sets the division of user groups and permissions, especially in general desktop or home systems, the Administrator is often given the highest permissions on the server. Some children's shoes said that after the server is built according to the above method, the Web page can be opened, but an error will be reported, such as 500 or 401, basically, it is because of permissions. If 401 is the root of all permissions, 500 may be the server error caused by file writing prohibition when writing to the local database, please carefully check whether the website directory permission is sufficient.

How to check it? It's easy to open IIS, select a website or virtual directory in the list on the left, and then in the "operations" column on the right, select "Edit permission"> "security ",


(Permission to edit website directories in IIS)

Here we can see that my website directory permissions include "Everyone", "Authenticated Users", "SYSTEM", "Administrators" and other user groups or user names, and allows the "Everyone" User Group to read, execute, and list operations. Therefore, the script and content of the website are accessible or obtained by anyone. Some children's shoes have no permissions on their hard disks, you may not have the permission for Everyone.



(Access failure due to insufficient permissions)

In this case, you can add the Everyone or IIS_IUSRS access permission in "security" of the website directory folder. If you need to upload files, you can set a folder to readable, writable, and executable. You only need to check the required permissions,


(Set IIS_IUSRS permissions)

4. Set Miscellaneous

The children's shoes are in such a hurry. Now the website should be officially released. Don't worry. There is something to say !!

First, the default document

Some children's shoes say that the installation methods you mentioned are all configured. How to enable them or report an error, just like the following error:

HTTP 403.14-Forbidden
The Web server is configured to not list the contents of this directory.


(Default document error not found on the website)

However, if you call http: // localhost: 8080/Default. aspx can be accessed again, because the default IIS documentation is as follows: default.htm?default.asp;index.htm=index.html#iisstart.htm, default. aspx (the Windows system is case insensitive, so the website published on IIS is case insensitive). If your home page file is not included in the above file, if you do not enter the document name, it cannot be accessed by Default (here I intentionally deleted the Default. aspx). Therefore, to address this issue, set the default document by yourself. The method is as follows (Here we assume you want to log on to the php website ):


(Add default document)

After adding the default document, you can directly tap the domain name, IP address, and port number to use the default page!

2. database connection string

Some children's shoes use Windows Authentication during local testing, so the connection string that VS automatically generates to Web. config is as follows:

<add name="ExampleConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Example;Integrated Security=True"      providerName="System.Data.SqlClient" />
If the connection string is directly used on the website, the webpage prompts:

The requested Database "Example" cannot be opened ". Logon Failed.

User 'iis APPPOOL \ ultappapppool 'Login Failed.

:


(Database exception)

Therefore, you must note that before attaching a website to a real IIS server, you must modify the Web. the string in config to ensure that the database uses SQL Server Authentication. If the database is installed on the local machine, set Data Source to localhost, 1433, as shown in the following code:

<add name="ConnectionString" connectionString="Data Source=localhost,1433;Initial Catalog=Example;User ID=sa;Password=123456" providerName="System.Data.SqlClient"/>

Third,. NET Framework Version

Especially in Windows 7, only supported by default. NET Framework 3.5, if. the installation sequence of NET Framework 4 and IIS is different. NET is not registered in IIS, so it is recommended that you install it first. NET Framework, or install IIS first, run cmd as an administrator before the website is mounted, and then enter X: Windows \ Microsoft. NET \ Framework \ v4.0.30319 (64-bit: X: Windows \ Microsoft. NET \ Framework64 \ v4.0.30319. X indicates the system installation disk. For example, the command "aspnet_regiis.exe-I" is executed after the command is executed. NET4 is registered with IIS to run IIS properly. net4.

In addition, if you select. NET4 during application development, and the website application chooses. NET2, it will not work.

Both of these are running framework exceptions and must be correctly configured; otherwise, an error will be reported!


(Select the correct application pool)

Fourth, disable debugging information

Debugging information is generally useful for local development. After the official release, some website information will be exposed if it is visible to visitors, and the developer is very amateur. Therefore, after the official deployment, disable debugging information as follows:

Modify Web. config and modify the following content

<system.web>      <compilation debug="true" targetFramework="4.0" />    </system.web>
After modification
<system.web>      <compilation debug="false" targetFramework="4.0" />    </system.web>
In this way, the debugging information for remote access is disabled.

Fifth, add the MIME type

Support for accept format files. If the MIME type is not added, HTML5 is not easy to implement. Other files, such as apk and ipa installation packages, are not commonly used, you also need to manually add it in IIS. If you do Not add it, the "404 Not Found" error will be reported. The method to add it is as follows:


(Add MIME type)

Sixth, other settings

Other settings include access control, IP address filtering, reverse proxy, SSL, log, CGI, etc. This configuration is based on personal needs and is not very difficult, unless you want to run Java on IIS. For reverse proxy of IIS, students can stamp another blog post: "direction proxy on IIS". In the future, I will continue to write a tutorial on creating a Web server for beginners, it covers PHP on Nginx, Apache, and IIS. Thank you for your attention!


Reprinted please indicate the source: http://blog.csdn.net/yuanguozhengjust/article/details/25747729

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.