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

How to use Nginx to build WCF Cluster

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

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use Nginx to build WCF cluster". In daily operation, I believe many people have doubts about how to use Nginx to build WCF cluster. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use Nginx to build WCF cluster". Next, please follow the editor to study!

One: prepared materials

\ 1. Needless to say, a picture is worth a thousand words. The servers in the figure are all virtualized by vmware, as shown in the following figure:

Three windows machines, two windows servers for WCF (192.168.23.187192.168.23.188), and one server for Client (192.168.23.1)

A Centos machine that hosts the web complex equalization nginx (192.168.23.190).

Add host mapping to all Client Hosts files: [192.168.23.190 cluster.com] to facilitate access to the ip address of the server where nginx resides in the form of a domain name.

Second, environmental construction

1. WCF program

Since it is a test, it must be a simple program, and the code is not fully given.

Public class HomeService: IHomeService {public string DoWork (string msg) {var ip = Dns.GetHostAddresses (Dns.GetHostName ()) .FirstOrDefault (I = > i.AddressFamily = = AddressFamily.InterNetwork). ToString (); return string.Format ("current request is returned by server= {0}", ip);}}

App.Config code

"v4.0" sku= ".NET Framework, Version=v4.5.2" / > ">" true "httpsGetEnabled=" true "/ >" false "/ >" WcfService.HomeService ">" / HomeService "binding=" basicHttpBinding "contract=" WcfService.IHomeService ">" localhost "/ >" mex "binding=" mexHttpBinding "contract=" IMetadataExchange "/ >" http://192.168.23.187:8733" / >

Because the ip addresses of the two machines on windows are 192.168.23.187192.168.23.188, pay attention to the baseAddress address in config when you deploy.

2. Nginx building on centos

Nginx I think you still use more, go to the official website to download the latest [nginx-1.13.6]: http://nginx.org/en/download.html, download, is the regular three axe installation!

[root@localhost nginx-1.13.6] # / configure-- prefix=/usr/myapp/nginx [root@localhost nginx-1.13.6] # make & & make install

Then find the conf file under the nginx installation directory and modify the nginx.conf configuration inside.

The detailed configuration is as follows, pay attention to the following "standard red" place, the weight is called according to 1:5, about other configurations, you can search on the Internet.

# user nobody;worker_processes 1 the errorless 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 {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;#tcp_nopush on;#keepalive_timeout 0tkeepalivekeepalivetimeout 65 * Server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;proxy_pass http://cluster.com;# sets the host header and the real address of the client so that the server can obtain the real IPproxy_set_header X-Forwarded-Host of the client $host;proxy_set_header X-Forwarded-Server $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for Proxy_set_header X-Real-IP $remote_addr;} # error_page 404 / 404.html php$ # redirect server error pages to the static page / 50x.html#error_page 502 503 504 / 50x.htmlX location = / 50x.html {root html;} # proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~\. Php$ {# html #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~\. Php$ {# root html;# fastcgi_pass 127.0.0.1 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 8000X # listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;#} #} # HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m # ssl_ciphers HIGHVERA NULLV MD5 cross # ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;#} #}

3. Program construction on client side

The first thing to do is to map 192.168.23.190 to the native host, because the service is not available to third parties, so adding host is easy.

192.168.23.190 cluster.com

Then the client side program adds the service reference, and because the host mapping is added, the service reference address is "http://cluster.com"." The code is as follows:

Class Program {static void Main (string [] args) {for (int I = 0; I "hello world!"); Console.WriteLine (info); System.Threading.Thread.Sleep (1000);} Console.Read ();}

Finally, let's execute the following procedure to see if the back-end wcf is called according to the weight 1:5 in the 1000 loops.

See, isn't that awesome? I just need to access the service through cluster.com, and nginx will automatically give me the complex equilibrium, which is the very simplified wcf complex equilibrium in our development.

At this point, the study on "how to use Nginx to build WCF clusters" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report