Configure http and tcp for Nginx, and httptcp for Nginx
Ejabberd + riak is being obtained recently. In fact, the configuration of these two items is quite pitfall, and then how to configure these two items, I will take the time to write the detailed configuration process. For Server Load balancer, I know that Nginx, LVS, and HAProxy have their own advantages and disadvantages. Let's take a look at what Server Load balancer is.
Server Load balancer is a server set composed of multiple servers in a symmetric manner. Each server is equivalent and can provide services independently without the assistance of other servers. Through a load balancing technology, requests sent from outside are evenly distributed to a server in the symmetric structure, and the server receiving the requests independently responds to the customer's requests. The server Load balancer can evenly distribute customer requests to the server array, so as to quickly obtain important data and solve a large number of concurrent access service problems. This cluster technology can achieve performance close to that of large hosts with minimal investment. -- From du Niang
Let's take a look at Nginx today.
1. Local Environment:
Ubbuntu 14
Pcre-8.38 portal --> pcre
Nginx-1.9.12 portal --> nginx
Ii. Installation
1. Decompress two packages respectively.
1 # unzip pcre and rename the folder 2 tar zxvf./pcre-8.38.tar.gz3 mv pcre-8.38 pcre4 # unzip nginx and rename the folder 5 tar zxvf./nginx-1.9.12.tar.gz6 mv nginx-1.9.12 nginxView Code
2. Install Dependencies
1 sudo apt-get install-y gcc g ++ makeView Code
3. Install pcre
1 cd./pcre2./configure prefix =/usr/local/pcre3 make & make installView Code
4. Install nginx
1 # enter the nginx folder 2 cd .. /nginx3 # Add parameter compilation 4. /configure -- prefix =/usr/local/nginx -- pid-path =/var/run/nginx. pid -- with-http_stub_status_module -- with-http_ssl_module -- with-pcre = stream -- with-pcre =/programs/pcreView Code
In this step, pay attention to the following points:
First, -- with-pcre = stream. Since nginx1.9.0, tcp Server Load balancer is supported, but this function is not available by default, this parameter can be used to balance the load of tcp Venus.
Second, -- with-pcre, which requires you to locate the source code of your pcre, whether or not you have installed pcre.
The third point is about openssl. When you encounter the following error, install Openssl
1 # error 1. openssl2 must be installed. /configure: error: SSL modules require the OpenSSL library.3 You can either do not enable the modules, or install the OpenSSL library4 into the system, or build the OpenSSL library statically from the source5 with nginx by using -- with-openssl = <path> option.6 # install openssl7 sudo apt-get install-y opensslView Code
Fourth, zlib. If you encounter the following error, install libssl-dev
1 # error, libssl-dev2 needs to be installed. /configure: error: the HTTP gzip module requires the zlib library.3 You can either disable the module by using -- without-http_gzip_module4 option, or install the zlib library into the system, or build the zlib library5 statically from the source with nginx by using -- with-zlib = <path> option.6 # install libssl-dev7 sudo apt-get install-y libssl-dev8 #. /After configure is passed, start compiling 9 sudo make & make installView Code
Now you can go to the/usr/local/nginx/sbin/directory to start Nginx. If you open your browser and enter the URL, you can see the welcome page of Nginx.
Congratulations, Your Nginx installation is successful. Configure the following.
3. Add Nginx to PATH
1 # edit/etc/bash. bashrc2 sudo vim/etc/bash. bashrcView Code
Add the following code at the bottom
1 # Add the following code 2 if [-d "/usr/local/nginx/sbin"]; then3 PATH = "$ PATH: /usr/local/nginx/sbin "4 fi5 # Save and exit 6 # refresh configuration 7 source/etc/bash. bashrcView Code
Now you can use nginx to start it anywhere.
Iv. Configuration
1. Http
Your conf file is in/usr/local/nginx/conf and is called nginx. conf. You need to configure it. Here is a simple example to show how to configure it.
1 http {2 upstream backend {3 server 10.0.1.11: 1234; 4 server 10.0.1.12: 1234; 5} 6 server {7 listen 80; 8 server_name example.com; 9 location/{10 limit_verification t GET {11 deny all; 12} 13 proxy_pass http: // backend; 14} 15} 16}View Code
The upstream part sets the address you want to load. You can add weight to set the weight.
Proxy_pass must be followed by http: // upstreamname. Then, you can restart your nginx to verify your configuration.
2. tcp
Or change the conf file, as shown in the following example:
1 stream {2 upstream backend {3 server 10.17.0.1: 1234; 4 server 10.17.0.2: 1234; 5} 6 server {7 listen 8080; 8 proxy_connect_timeout 1 s; 9 proxy_timeout 3 s; 10 proxy_pass backend; 11} 12}View Code
Note that the proxy_pass parameter is set to upstreamname without http ://
In this way, you can access the tcp interface.
In fact, there are still many configuration items related to Nginx. I may explain the actual software configuration in the future. I wrote this article first, hoping to help you.
Reprinted please note
Author: Spring of Li xiao'er
Address: http://www.cnblogs.com/LittleTwoLee/p/5258279.html