Nginx + IIS + Web front-end (SpringMVC) -- server load balancer (1)

Source: Internet
Author: User
Tags sendfile
: This article mainly introduces the Nginx + IIS + Web front-end (SpringMVC)-server load balancer (1). If you are interested in PHP tutorials, refer to it. Introduction

When developing a large Web project, if our web is published on the IIS of a server, when a large number of requests are sent to the IIS service, the computer will crash easily. So we thought, why don't we put our services on multiple computers? In this way, a request is sent to 192. 168. **. 252: 8070, we can make the next request to 192. 168. **. 253: 8071, which can reduce the pressure on our servers.

Now there is a problem. how do users send requests to different servers? At this time, Nginx is required.

Now let me introduce how to publish. net Web services on Nginx.

Nginx is an unzipping package. we only need to decompress the package on the Nginx server, modify the configuration file, and then install Nginx.

Install and configure Nginx

Decompress Nginx to the root directory of drive C:

We can see the file directory under Nginx. here we want to modify the nginx. conf file under the conf folder:

Here is a rough explanation:

The file is as follows:

# User nobody; worker_processes 1; # Number of worker processes. multiple worker processes can be configured. # error_log logs/error. log; # error_log logs/error. log notice; # error_log logs/error. log info; # pid logs/nginx. pid; events {worker_connections 1024; # maximum number of connections to a single process (maximum number of connections = number of connections * number of processes)} # set the http server, using its reverse proxy function, server load balancer supports http {include mime. types; # default_type application/octet-stream; # default file type # log_format main '$ remote_addr-$ remote_user [$ time_local] "$ reques T "'#' $ status $ body_bytes_sent" $ http_referer "'#'" $ http_user_agent "" $ http_x_forwarded_for "'; # access_log logs/access. log main; sendfile on; # enable the efficient file transmission mode. the sendfile command specifies whether nginx calls the sendfile function to output files. for common applications, set it to on, if it is used for application disk I/O heavy load applications such as downloading, you can set it to off to balance the disk and network I/O processing speed and reduce the system load. Note: If the image is not displayed properly, change it to off. # Tcp_nopush on; # keepalive_timeout 0; keepalive_timeout 65; # Long connection timeout time, in seconds gzip on; # enable Gizp compression # server cluster upstream netitcast.com {# server cluster name server 127.0.0.1: 8030 weight = 1; # server configuration weight indicates weight. a higher weight indicates a higher probability of allocation. Server 127.0.0.1: 8040 weight = 1 ;}# current Nginx configuration server {listen 8090; # listen to port 80, you can change it to another port server_name localhost; ############# domain name of the current service # charset KOI8-R; # access_log logs/host. access. log main; # location/{# root html; # index index.html index.htm; #} location/{proxy_pass http://netitcast.com ; Proxy_redirect default;} # location ~ \. (Jpg | png | jpeg | bmp | gif | swf | css) $ # {# expires 30d; # root/nginx-1.4.7; # root: # break; #}# error_page 404/404 .html; # redirect server error pages to the static page/50x.html # error_page 500 502 503 504/50 x.html; location =/50x.html {root html;} # proxy the PHP scripts to Apache listening on 127.0.0.1: 80 ## location ~ \. Php $ {# proxy_pass http://127.0.0.1 #}# Pass the PHP scripts to FastCGI server listening on 127.0.0.1: 9000 ## location ~ \. Php $ {# root html; # fastcgi_pass 127.0.0.1: 9000; # fastcgi_index index. php; # fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name; # include fastcgi_params; #}# deny access. htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\. Ht {# deny all ;#}# another virtual host using mix of IP-, name-, and port-based configuration # server {# listen 8000; # listen somename: 8080; # server_name somename alias another. alias; # location/{# root html; # index index.html index.htm; #}#}# HTTPS server # server {# listen 443; # server_name localhost; # ssl on; # ssl_certificate cert. pem; # ssl_certificate_key cert. key ;# Ssl_session_timeout 5 m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH :! ANULL :! MD5; # ssl_prefer_server_ciphers on; # location/{# root html; # index index.html index.htm ;#}#}}

To be modified:

# Server cluster upstream netitcast.com {# server cluster name server 127.0.0.1: 8030 weight = 1; # server configuration weight indicates weight. a higher weight indicates a higher probability of allocation. Server 127.0.0.1: 8040 weight = 1 ;}# current Nginx configuration server {listen 8090; # listen to port 80, you can change it to another port server_name localhost; ############# domain name of the current service # charset KOI8-R; # access_log logs/host. access. log main; # location/{# root html; # index index.html index.htm; #} location/{proxy_pass http://netitcast.com; proxy_redirect default ;}

We can see the name of the server cluster:

Server ip: port

We will release the ip address and port number of the server for our project, and we can write the ip address and port number here. The following weight is the weight, that is, if both servers are 1, the request is, the first request is accessed on port 8030, and the second request is accessed on port 8040.

Server {listen 8090} is the port number of the nginx listener, that is, we only need to access the ip address and port number of the Nginx server to access the services in our server cluster.

Nginx principles:

Nginx has been configured. in the next blog, we published our Web service to our IIS.

Reference Blog: http://blog.csdn.net/zhanghan18333611647/article/details/50282951

The above introduces Nginx + IIS + Web front-end (Spring MVC)-server load balancer (I), including some content, and hope to be helpful to PHP tutorials.

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.