标签:nginx
客户端访问http://bbs.upl.com --> 解析到 nginx_proxy 172.16.2.8
nginx_proxy作为反向代理,实现动静分离:
如果是已知的静态页面请求: 调度给squid
图片,文本.txt,.html,.htm,客户端代码文件.js,.css
其他未知的请求(包括php)调度给lnmp节点
nginx_proxy 使用宿主机
br0 172.16.2.8 <---模拟连接到公网
virbr1 192.168.110.1 <---模拟连接到内网
lnmp或lamp
eth0 192.168.110.103
gw 192.168.110.1 可选
squid
eth0 192.168.110.104
gw 192.168.110.1 可选
一、配置nginx_proxy
# yum install pcre pcre-devel -y
nginx-1.0.15.tar.gz
# ./configure --prefix=/usr/local/nginx --with-pcre --user=daemon --group=daemon --with-http_stub_status_module
# make -j4 && make install
为了方便执行该命令:
# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
# vim /usr/local/nginx/conf/nginx.conf
user daemon;
worker_processes 2;
error_log logs/error.log;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
upstream suqidservs {
server 192.168.110.104 max_fails=3 fail_timeout=30s;
}
upstream lnmpservs {
server 192.168.110.103 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name bbs.upl.com upl.com;
location ~* \.(gif|bmp|jpeg|jpg|png|css|js|html|htm|txt)$ {
proxy_pass http://suqidservs;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
location / {
proxy_pass http://lnmpservs;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
# nginx
二、部署lnmp节点
# cat /usr/local/nginx/conf/nginx.conf
user daemon;
worker_processes 2;
error_log logs/error.log;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
# 更改了日志记录客户端IP的字段
log_format main ‘$http_X_Real_IP - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
# access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
....
....
server {
listen 80;
server_name bbs.upl.com;
access_log logs/bbs.access.log main;
location / {
root /web/bbs.upl.com/wwwroot/;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /web/bbs.upl.com/wwwroot/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
....
.....
}
# nginx
# service mysql5 start
# service php-fpm start
三、部署squid
作为反向加
速代理
参考ulp_05.txt
# yum install squid -y
shell> vim /etc/squid/squid.conf
http_access allow all <---把原来的deny all 修改成 allow all
http_port 80 accel vhost vport <---修改监听端口的参数,并且设定模式为加速模式
定义 192.168.110.104为父节点,他是原始节点,squid没有的,不能处理的请求都去问它
cache_peer 192.168.110.103 parent 80 0 originserver name=web1
如果squid接受到的客户端访问的请求是使用bbs.upl.com域名的,这些请求都应该和web1节点关联系
cache_peer_domain web1 bbs.upl.com
visible_hostname squid1.upl.com
cache_dir ufs /var/spool/squid 20480 16 256
cache_mem 256 MB
maximum_object_size_in_memory 2048 KB
maximum_object_size 102400 KB
logformat combined %{X-Real-IP}>h %ui %un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
access_log /var/log/squid/access.log combined
# service squid start
本文出自 “linux” 博客,谢绝转载!
标签:nginx
原文地址:http://linuxjs.blog.51cto.com/5876369/1679659