Home Backend Development PHP Tutorial Nginx + IIS + Web front end (Spring MVC) - load balancing (1)

Nginx + IIS + Web front end (Spring MVC) - load balancing (1)

Jul 29, 2016 am 09:01 AM
html index location nginx server

Introduction

When we develop large-scale web projects, if our web is published on IIS on a server, when a large number of requests are made to the IIS service, the computer will easily crash. So we thought, why don't we put our services on multiple computers? In this way, when the previous request goes to 192.168.**.252:8070, we can make the next request go to 192.168.**.253:8071, which can reduce the pressure on our server.

Now there is a problem, how to send the Request issued by USer to different servers? At this time, Nginx is needed.

Now I will introduce the .net web service published on Nginx.

Nginx is an unzipped package. We only need to unzip it on the Nginx server, modify the configuration file, and Nginx will be installed.

Nginx installation and configuration

Nginx is extracted to the root directory of the C drive:

Nginx + IIS + Web前端(Spring MVC)——负载均衡(一)

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

A rough explanation:

The file looks like this:

<span style="font-size:18px;">#user  nobody;
worker_processes  1;#工作进程的个数,可以配置多个

#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;#单个进程最大连接数(最大连接数=连接数*进程数)
}


#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
    include       mime.types; #文件扩展名与文件类型映射表
    default_type  application/octet-stream;#默认文件类型

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65; #长连接超时时间,单位是秒

    gzip  on;#启用Gizp压缩
	
	#服务器的集群
    upstream  netitcast.com {  #服务器集群名字  		
		server    127.0.0.1:8030 weight=1;		#服务器配置   weight是权重的意思,权重越大,分配的概率越大。
		server    127.0.0.1:8040 weight=1;		
	}	

	#当前的Nginx的配置
    server {
        listen       8090;#监听80端口,可以改成其他端口
        server_name  localhost;##############	当前服务的域名

        #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  /50x.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 to .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  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
</span>
Copy after login

What needs to be modified:

<span style="font-size:18px;">	#服务器的集群
    upstream  netitcast.com {  #服务器集群名字  		
		server    127.0.0.1:8030 weight=1;		#服务器配置   weight是权重的意思,权重越大,分配的概率越大。
		server    127.0.0.1:8040 weight=1;		
	}	

	#当前的Nginx的配置
    server {
        listen       8090;#监听80端口,可以改成其他端口
        server_name  localhost;##############	当前服务的域名

        #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;
        }
</span>
Copy after login

We can see that the server cluster Name:

server ip: port

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

server{ listen 8090} is the listening port number of nginx. That is, we only need to access the IP and port number of the Nginx server to access the services in our server cluster.

The principle of Nginx:

Nginx + IIS + Web前端(Spring MVC)——负载均衡(一)

Nginx is configured. In the next blog, we will publish 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) - load balancing (1), including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

HTML: Is It a Programming Language or Something Else? HTML: Is It a Programming Language or Something Else? Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to create a mirror in docker How to create a mirror in docker Apr 15, 2025 am 11:27 AM

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

How to run nginx apache How to run nginx apache Apr 14, 2025 pm 12:33 PM

To get Nginx to run Apache, you need to: 1. Install Nginx and Apache; 2. Configure the Nginx agent; 3. Start Nginx and Apache; 4. Test the configuration to ensure that you can see Apache content after accessing the domain name. In addition, you need to pay attention to other matters such as port number matching, virtual host configuration, and SSL/TLS settings.

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

See all articles