Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case Analysis of simple deployment of Nginx+IIS

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you the relevant knowledge points of Nginx+IIS simple deployment case analysis. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Introduction to nginx:

Nginx ("engine x") is a high-performance http and reverse proxy server, as well as an imap/pop3/smtp proxy server. Nginx was developed by igor sysoev for the second most visited rambler.ru site in Russia, and it has been running on the site for more than four years. Igor publishes the source code as a bsd-like license. In the four years since the release of nginx, nginx has been known for its stability, rich feature set, sample configuration files, and low consumption of system resources. At present, major domestic portals have deployed nginx, such as Sina, NetEase, Tencent, etc.; several important domestic video sharing sites have also deployed nginx, such as six rooms, Ku6 and so on. Recently, it is found that nginx technology is becoming more and more popular in China, and more and more websites begin to deploy nginx. It's all said on the Internet.

Nginx installation

Nginx is a lightweight web server / reverse proxy server and email (imap/pop3) proxy server, and is distributed under a bsd-like protocol. Developed by igor sysoev, a Russian programmer, it is used by Russia's large portal website and search engine rambler. It is characterized by less memory and strong concurrency ability. in fact, the concurrency ability of nginx does perform well in the same type of web server. Chinese mainland uses nginx website users: Baidu, Sina, NetEase, Tencent and so on.

The latest version of nginx is 1.9.3. What I download here is the window version. Generally, the actual scenarios are installed under the linux system. Because the linux system is currently being explored, it will not be introduced here. Official download address:. After the download is completed, the unzipped nginx.exe launches nginx. After startup, you will see nginx in the process.

To achieve load balancer, you need to modify the configuration information of conf/nginx.conf. Restart the nginx service after modifying the configuration information, which can be achieved through the nginx-s reload instruction. Here we use a batch provided by ants to operate.

Put the nginx.bat file in the same folder as nginx.exe and run it directly. All the files used in this article will be provided at the end of the article.

Site construction and configuration

1. Set up two iis sites

There is only a simple index page under the site to output the current server information. Since I didn't have two machines, I deployed both sites to the local machine, bound to ports 8082 and 9000, respectively.

Protected void page_load (object sender, eventargs e) {label0.text = "request start time:" + datetime.now.tostring ("yyyy-mm-dd hh:mm:ss"); label1.text = "server name:" + server.machinename;// server name label2.text = "server ip address:" + request.servervariables ["local_addr"] / / server ip address label3.text = "http access port:" + request.servervariables ["server_port"]; / / http access port "label4.text =" .net interpretation engine version: "+" .net clr "+ environment.version.major +". "+ environment.version.minor +". "+ environment.version.build +". "+ environment.version.revision / / .net interpretation engine version label5.text = "server operating system version: + environment.osversion.tostring (); / / server operating system version label6.text =" server iis version: "+ request.servervariables [" server_software "]; / / server iis version label7.text =" server domain name: "+ request.servervariables [" server_name "] / / Server domain name label8.text = "absolute path to virtual directory:" + request.servervariables ["appl_rhysical_path"]; / / absolute path to virtual directory label9.text = "absolute path to execution file:" + request.servervariables ["path_translated"]; / / absolute path to execution file label10.text = "Total virtual directory session:" + session.contents.count.tostring () / / Total virtual directory session label11.text = "Total virtual directory application:" + application.contents.count.tostring (); / / Total virtual directory application label12.text = "domain name host:" + request.servervariables ["http_host"]; / / domain name host label13.text = "server locale language:" + request.servervariables ["http_accept_language"] / / Server regional language label14.text = "user information:" + request.servervariables ["http_user_agent"]; label14.text = "number of cpu:" + environment.getenvironmentvariable ("number_of_processors"); / / number of cpu label15.text = "cpu type:" + environment.getenvironmentvariable ("processor_identifier"); / / cpu type label16.text = "request source address:" + request.headers ["x-real-ip"];}

two。 Modify nginx configuration information

Modify the nginx listening port and modify the listen node value under http server. Since native port 80 has been occupied, I will listen to port 8083 instead.

Listen 8083

Add upstream (server cluster) under the http node. Server sets up the information of the cluster server. I have built two sites here and configured two messages.

# the server cluster name is jq_oneupstream jq_one {server 127.0.0.1 server 9000; server 127.0.0.1 server 8082;}

Find the location node modification under the http node

Location / {root html;index index.aspx index.html index.htm; # modify the home page to index.aspx# where jq_one corresponds to the cluster name set by upstream proxy_pass http://jq_one;# sets the host header and the real address of the client, so that the server can get the real ipproxy_set_header host of the client $host;proxy_set_header x-real-ip $remote_addr;proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;}

Remember to restart the nginx service after modifying the configuration file. The final complete configuration file information is as follows

3. Running result

Visit http://127.0.0.1:8083/index.aspx, visit several times, and focus on the red section.

As you can see, our request is distributed to the 8082 site and the 9000 site, and the first is the 8082 site and the second 9000. Such a result proves that our load balancer has been built successfully. Try to shut down 9000 of these sites, and then refresh the page to find that the output http port has been 8082, which means that one of the sites is dead, as long as there is a good site, our service is still available.

Analysis of problems

Although we have set up a load balancing site, there are still the following problems.

1. If the site uses session and requests are evenly distributed between two sites, then there must be a session sharing problem, how to solve it?

Use the database to save session information and use nginx to assign requests for the same ip to the fixed server, modified as follows. Ip_hash calculates the ip corresponding hash value and assigns it to the fixed server

Upstream jq_one {

Server 127.0.0.1:8082

Server 127.0.0.1:9000

Ip_hash

}

Set up a redis server, and read all the session reads from the redis server. A later article will introduce the use of distributed cache redis

two。 Administrator updates site files, how to do, there are only two servers, you can manually update files to two servers, if it is 10, then manual operation must not be feasible

Multi-server site updates can use the goodsync file synchronizer, which automatically detects new changes to the file and then synchronizes it to other servers. You can use rsync under linux

3. The file upload function in the site will assign files to different servers, how to solve the file sharing problem.

Use a file server to store all files on that server, where file operations are read and written. There will also be a problem here, where there is a read and write limit on the file server.

4. The server configuration of the load is different, some are high and some are low. Can you let the server with high configuration handle more requests?

Here, there are several algorithms for load balancing: rotation method, hash method, least join method, minimum missing method, fastest response method, weighting method. We can use the weighting method to allocate requests here.

Upstream jq_one {

Server 127.0.0.1:8082 weight=4

Server 127.0.0.1:9000 weight=1

}

Set the weight of each server to allocate the request station through weight. The higher the value, the more it will be allocated.

5. Since the request is forwarded through nginx, can the actual ip address requested by the user be obtained in the code?

The answer is yes, set the following request header information in the localtion node

# set the host header and the real address of the client, so that the server can obtain the real ipproxy_set_header host $host;proxy_set_header x-real-ip $remote_addr;proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for of the client

The real ip can be obtained through request.headers ["x-real-ip"] in the code.

These are all the contents of the article "Nginx+IIS simple deployment example Analysis". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report