As the Internet user visits the project rising a single point web server is unable to meet the business processes of large high concurrent high load, in order to make the web server load balancing scheme, set up Nginx intend to use load balancing server, the user requests assigned to N servers to relieve pressure on the server.
About Nginx:
Nginx ( "the X-Engine") is a high-performance HTTP server and reverse proxy, also a IMAP / POP3 / SMTP proxy server. Nginx is made Igor Sysoev of Russia visited the second Rambler.ru site development, it has been running for more than four years at the site and more. Igor the source code to BSD license issued in the form. Since Nginx issued for four years, Nginx already because of its stability, rich feature set, simple configuration files and low system resource consumption of the famous. At present, the major portals have been deployed Nginx, like Sina, Netease, Tencent and other; domestic several important video sharing site also deployed Nginx, like six rooms, cool, 6 and so on. Newly discovered Nginx technology in China is becoming more fiery, more and more sites began to deploy Nginx.
install nginx
Nginx is a lightweight Web server / reverse proxy server and e-mail (IMAP / POP3) proxy server, and released under a BSD-like agreement. The program developed by Russian designer Igor Sysoev, Russia for large-scale web portal and search engine Rambler (Russian: Рамблер) use. It features occupy less memory, high concurrency, the ability to do concurrent nginx fact the same type of web server performance is better, mainland China use nginx web site users are: Baidu, Sina, Netease, Tencent and so on.
This is the window I downloaded version 1.9.3 of the actual scenes are usually installed in linux system, because the system is currently under exploration in linux is not presented here. Official Download: nginx-1.9.3.zip After the download is complete extract the run nginx.exe started the nginx, and nginx will see after starting on the inside processes.
Write a batch command easily changed to ANSI encoding format can start if the Chinese garbled, the new script file, the effect is as follows:
@echo off
rem 提供Windows下nginx的启动,重启,关闭功能
echo ==================begin========================
cls
::ngxin 所在的盘符
set NGINX_PATH=D:
::nginx 所在目录
set NGINX_DIR=D:\nginx\nginx-1.9.3\
color 0a
TITLE Nginx 管理程序增强版
CLS
echo.
echo. ** Nginx 管理程序 ***
echo. *** create 2019-03-31 ***
echo.
:MENU
echo. ***** nginx 进程list ******
::tasklist|findstr /i "nginx.exe"
tasklist /fi "imagename eq nginx.exe"
echo.
if ERRORLEVEL 1 (
echo nginx.exe不存在
) else (
echo nginx.exe存在
)
echo.
::*************************************************************************************************************
echo.
echo. [1] 启动Nginx
echo. [2] 关闭Nginx
echo. [3] 重启Nginx
echo. [4] 刷新控制台
echo. [5] 重新加载Nginx配置文件
echo. [6] 检查测试nginx配置文件
echo. [7] 查看nginx version
echo. [0] 退 出
echo.
echo.请输入选择的序号:
set /p ID=
IF "%id%"=="1" GOTO start
IF "%id%"=="2" GOTO stop
IF "%id%"=="3" GOTO restart
IF "%id%"=="4" GOTO MENU
IF "%id%"=="5" GOTO reloadConf
IF "%id%"=="6" GOTO checkConf
IF "%id%"=="7" GOTO showVersion
IF "%id%"=="0" EXIT
PAUSE
::*************************************************************************************************************
::启动
:start
call :startNginx
GOTO MENU
::停止
:stop
call :shutdownNginx
GOTO MENU
::重启
:restart
call :shutdownNginx
call :startNginx
GOTO MENU
::检查测试配置文件
:checkConf
call :checkConfNginx
GOTO MENU
::重新加载Nginx配置文件
:reloadConf
call :checkConfNginx
call :reloadConfNginx
GOTO MENU
::显示nginx版本
:showVersion
call :showVersionNginx
GOTO MENU
::*************************************************************************************
::底层
::*************************************************************************************
:shutdownNginx
echo.
echo.关闭Nginx......
taskkill /F /IM nginx.exe > nul
echo.OK,关闭所有nginx 进程
goto :eof
:startNginx
echo.
echo.启动Nginx......
IF NOT EXIST "%NGINX_DIR%nginx.exe" (
echo "%NGINX_DIR%nginx.exe"不存在
goto :eof
)
%NGINX_PATH%
cd "%NGINX_DIR%"
IF EXIST "%NGINX_DIR%nginx.exe" (
echo "start '' nginx.exe"
start "" nginx.exe
)
echo.OK
goto :eof
:checkConfNginx
echo.
echo.检查测试 nginx 配置文件......
IF NOT EXIST "%NGINX_DIR%nginx.exe" (
echo "%NGINX_DIR%nginx.exe"不存在
goto :eof
)
%NGINX_PATH%
cd "%NGINX_DIR%"
nginx -t -c conf/nginx.conf
goto :eof
::重新加载 nginx 配置文件
:reloadConfNginx
echo.
echo.重新加载 nginx 配置文件......
IF NOT EXIST "%NGINX_DIR%nginx.exe" (
echo "%NGINX_DIR%nginx.exe"不存在
goto :eof
)
%NGINX_PATH%
cd "%NGINX_DIR%"
nginx -s reload
goto :eof
::显示nginx版本
:showVersionNginx
echo.
%NGINX_PATH%
cd "%NGINX_DIR%"
nginx -V
goto :eof
Start bat file, select 1 start nginx, view the process, if the process is not found, it may be the error. View nginx logs
Common mistakes:
(1) port number is occupied
(2) nginx folder path with Chinese
It found nginx ports are occupied. We find nginx.conf configuration, modify the port as shown below.
Nginx and then start again, open the site localhost: 8800
nginx pretend success.
Nginx Load Balancing
Because I do not have a server, so the local analog nginx load balancing,
1. iis set up two sites
The establishment of two sites port numbers 8801 and 8802 in local
2. Modify the nginx configuration information
Add at http node upstream (server cluster), server setup is cluster server information, and I am here to build two sites, equipped with two pieces of information.
# Server cluster name Jq_one
upstream Jq_one {
Server 127.0.0.1:8801;
Server 127.0.0.1:8802;
}
Found at http modify node location node
LOCATION / {
the root HTML;
index Index.aspx index.html index.htm; # modified homepage for Index.aspx
# corresponds to the name of the cluster where jq_one disposed upstream
proxy_pass HTTP: // Jq_one;
}
3. Run results
Access localhost: 8800, and more visit several times, and each time is different.
A simple nginx load balancing is complete.
Precautions:
1: nginx.conf, with particular attention to the preparation of the format, nginx has strict requirements for the format, are particularly vulnerable and more space, modifying the best backup. :
2: After each change the configuration, remember to restart nginx