Centos7.2 load balancing by installing Nginx

  • 2020-05-24 06:43:17
  • OfStack

Download Nginx

To website to download the source code files, address: http: / / nginx org/en/download html, choose the latest version. I download the address is: http: / / nginx org download/nginx - 1.10.2. tar. gz, available wget command to download, you can download on windows system well to linux again.

Uninstall httpd

If the httpd service is installed by default, uninstall it. It doesn't matter if you don't uninstall it, it's just for the convenience of handling port 80 by default.


yum -y remove httpd

Unpack the


tar -xzvf nginx-xxxxxx.tar.gz

Install the compiler and the dependency libraries


yum install gcc gcc-c++ zlib-devel pcre-devel openssl-devel openssl-libs openssl -y

If it is already installed, it is not necessary

Pre-installation configuration

The cd command goes to the unzipped directory.


./configure --prefix=/usr/local/nginx

This will install Nginx to the /usr/local/nginx directory.

compile


make

The installation


make install

The installation is complete, and after configuring the environment variables, you don't need to use the absolute path to operate Nginx:


vim /etc/profile.d/http.sh

Add the following:


export PATH=/usr/local/nginx/sbin:$PATH

Active configuration:


source !$

Start the Nginx


nginx

Close and overload nginx with nginx-s followed by stop and reload, and start the service by running nginx directly. If the boot prompt port being used, you will need to find out the process of being used, or change/usr/local/nginx/conf/nginx conf listener ports in the file.

Visit Nginx

Type http://ip:port in the browser if "Welcome to nginx!" appears. The word, it proves the installation is successful. If not, make sure the firewall disables the port.

Load balancing configuration example


tar -xzvf nginx-xxxxxx.tar.gz
0

Once configured, remember to execute the following command to take effect the configuration


tar -xzvf nginx-xxxxxx.tar.gz
1

Related articles: