Nginx load-balanced back-end RS for real IP
Front End proxy configuration
####################
Worker_processes 1;
Events {
Worker_connections 1024;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
Upstream Backend {
Server 10.0.0.3:80 max_fails=3 fail_timeout=30s;
Server 10.0.0.4:80 max_fails=3 fail_timeout=30s;
}
server {
Listen 80;
server_name www.lvnian.com lvnian.com;
Location/{
root HTML;
Index index.html index.htm;
Proxy_pass Http://backend;
Proxy_redirect off;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
# #上面四个是记录真实IP, and configurations that differentiate back-end different services
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
}
#####################################
server {
Listen 80;
server_name bbs.lvnian.com lvnian.com;
Location/{
root HTML;
Index index.html index.htm;
Proxy_pass Http://backend;
Proxy_redirect off;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
# #上面四个是记录真实IP, and configurations that differentiate back-end different services
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
}
}
##################################################
Back-End RS Configuration
server {
Listen 80;
server_name www.lvnian.com;
Set_real_ip_from 10.0.0.0/24;
Real_ip_header X-real-ip;
##### #这两个参数是记录真实IP的
Location/{
root HTML;
Index index.html index.htm;
}
Error_page 502 503 504/50x.html;
Access_log Logs/www.access.log;
Error_log Logs/www.error.log error;
Location =/50x.html {
root HTML;
}
Location ~. *\. (PHP|PHP5) {
Root www;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include fastcgi.conf;
}
}
#######################################
Worker_processes 1;
Events {
Worker_connections 1024;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
server {
Listen 80;
server_name www.lvnian.com;
Location/{
root HTML;
Index index.html index.htm;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
#########
Set_real_ip_from 10.0.0.0/24;
Real_ip_header x-forwarded-for;
##### #这两个参数是记录真实IP的
}
################################################
server {
Listen 80;
server_name bbs.lvnian.com;
Location/{
Root BBS;
Index index.html index.htm;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
#########
Set_real_ip_from 10.0.0.0/24;
Real_ip_header x-forwarded-for;
##### #这两个参数是记录真实IP的
}
}
################################################################################
If the back-end RS is added to record the true IP, the syntax check fails, possibly the--with-http_realip_module module is not installed.
In the installed Nginx service door, add Nginx module method as follows
# #添加新模块
1. View the commands of Nginx compile and install, which modules are installed
/application/nginx/sbin/nginx-v
2. Add the modules that need to be installed, recompile
Pkill Nginx
cd/home/lvnian/tools/nginx-1.6.2
./configure--user=nginx--group=nginx--prefix=/application/nginx-1.6.2--with-http_stub_status_module--with-http _realip_module--with-http_ssl_module
Make
Make it, but don't make install, or it will overwrite
Make
3. Replace the Nginx binary file:
Cp/app/nginx/sbin/nginx/app/nginx/sbin/nginx.bak
CP./objs/nginx/app/nginx/sbin/
4. Start Nginx
/application/nginx/sbin/nginx-v
/application/nginx/sbin/nginx-t
/application/nginx/sbin/nginx
#######################################################
Pkill Nginx
cd/home/lvnian/tools/nginx-1.6.2
./configure--user=nginx--group=nginx--prefix=/application/nginx-1.6.2--with-http_stub_status_module--with-http _realip_module--with-http_ssl_module
Make
Cp/application/nginx/sbin/nginx/application/nginx/sbin/nginx.bak
CP Objs/nginx/application/nginx/sbin/nginx
/application/nginx/sbin/nginx-v
/application/nginx/sbin/nginx-t
This article is from the "Technology Change Destiny" blog, please be sure to keep this source http://lvnian.blog.51cto.com/7155281/1697315
Nginx load-balanced back-end RS for real IP