实验需求:使用nginx搭建反向代理服务器,把用户的请求分发给后端的web服务器组192.168.100.1和192.168.100.2
内网web服务器192.168.100.1 内网接口eth0(192.168.1.254)
----------- nginx反向代理服务器------------ 公网客户端1.1.1.1
内网web服务器192.168.100.2 公网接口eth1(1.1.1.254)
CentOS 6.2实战部署Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm
使用Nginx搭建WEB服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm
搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm
CentOS 6.3下Nginx性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm
CentOS 6.3下配置Nginx加载ngx_pagespeed模块 http://www.linuxidc.com/Linux/2013-09/89657.htm
CentOS 6.4安装配置Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm
Nginx搭建视频点播服务器(仿真专业流媒体软件) http://www.linuxidc.com/Linux/2012-08/69151.htm
一.部署内网的网站服务器192.168.100.1
可以使用apache或nginx等软件搭建,此实验采用nginx搭建
1.安装软件并编辑配置文件
# vim /usr/local/nginx/conf/nginx.conf
http {
……
server {
listen 80;
server_name www.linuxidc.com
location / {
root html;
index index.html index.htm;
}
}
……
2.制作测试网页文件
# echo 192.168.100.1 > /usr/local/nginx/html/index.html
3.启动服务
# cd /usr/local/nginx/sbin
# ./nginx
二.部署内网的网站服务器192.168.100.2
1.安装软件并编辑配置文件
# vim /usr/local/nginx/conf/nginx.conf
http {
……
server {
listen 80;
server_name www.linuxidc.com
location / {
root html;
index index.html index.htm;
}
}
……
2.制作测试网页文件
# echo 192.168.100.2 > /usr/local/nginx/html/index.html //为了测试效果,2台服务器上创建不同的网页
3.启动服务
# cd /usr/local/nginx/sbin
# ./nginx
三.配置nginx反向代理服务器
1.安装软件并编辑配置文件
# vim /usr/local/nginx/conf/nginx.conf
……
http {
……
upstream sergrp { //定义源服务器组
server 192.168.100.1:80;
server 192.168.100.2:80;
}
server {
listen 80;
server_name www.linuxidc.com; //web主机名
location / {
root html;
index index.html index.htm;
proxy_pass http://sergrp; //调用服务器组
……
2.释放80端口并启动服务
# service httpd stop //本服务器若已启动web服务则关闭,或将其开启在别的端口
# chkconfig httpd off
# cd /usr/local/nginx/sbin
# ./nginx
更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2014-05/102219p2.htm
