In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "simple deployment methods of Nginx and IIS". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
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: nginx-1.9.3.zip. 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.
That's all for "simple deployment methods for Nginx and IIS". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.