Nginx 反向代理 动静分离
2015-09-08 00:38
525 查看
![](http://s3.51cto.com/wyfs02/M00/72/90/wKiom1XmnUuja0nMAACNkbOZ8S8165.jpg)
1、实验环境:
机器
10.0.10.8 Nginx proxy
10.0.10.12 Nginx静态
10.0.10.10 Ngins动态,LNMP平台,有个Tomcat服务
系统版本和内核
# cat /etc/redhat-release
CentOS release 6.6 (Final)
# uname -r
2.6.32-504.3.3.el6.x86_64
2、Nginx静态服务器的配置文件
# cat /application/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
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;
server {
listen 80;
server_name www.cui.com;
location / {
root /data/www;
index index.html index.htm;
}
}
}
简单的网页内容以及图片
# cat /data/www/index.html
<html>
<head>test</head>
<body>
This is static site!!
</body>
</html>
# ls /data/www/
1.png images index.html tomcat.png
3、Nginx动态服务器配置文件
# cat /application/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
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;
server {
listen 80;
server_name www.cui.com;
root /data/www;
location / {
root /data/www;
index index.php index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
简单的网页内容
# cat /data/www/index.php
<?php
echo "This is php dynamic site !!\n";
?>
4、Nginx proxy服务器配置文件
# cat /application/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server_tokens off;
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;
include proxy.conf; #proxy一些优化
upstream static_pools {
server 10.0.10.12:80 weight=1 max_fails=10 fail_timeout=10s;
}
upstream nginx_pools {
server 10.0.10.10:80 weight=1 max_fails=10 fail_timeout=10s;
}
upstream tomcat_pools {
server 10.0.10.10:8080 weight=1 max_fails=10 fail_timeout=10s;
}
server {
listen 80;
server_name www.cui.com;
#location / {
# index index.html index.htm;
# proxy_pass http://static_pools; #这里可以设置,也可以不设置,设置成静态默认就找静态,设置成动态默认就找动态
#}
location ~* \.(html|js|css|gif|jpg|jpeg|png|bmp|swf)$ {
proxy_pass http://static_pools; }
location ^~ /images/ {
proxy_pass http://static_pools; }
location ~ .*.(php|cgi|jhtml)$ {
proxy_pass http://nginx_pools; }
location ~ .*.(jsp)$ {
proxy_pass http://tomcat_pools; }
}
}
proyx优化的配置文件
# cat /application/nginx/conf/proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
5、验证效果
1.以下这个是默认访问到的静态网页
![](http://s3.51cto.com/wyfs02/M00/72/8C/wKioL1XmoAaSXiwPAAB5bv7M5jg289.jpg)
2.以下这个是访问到的以png结尾的静态图片
![](http://s3.51cto.com/wyfs02/M02/72/8D/wKioL1XmoPjRb-bBAALKtRUXfVI350.jpg)
3.以下这个是访问到的images目录的静态图片
![](http://s3.51cto.com/wyfs02/M00/72/90/wKiom1Xmn1nRSJu6AAU8_ATDZBg052.jpg)
4.以下是访问以php结尾的动态网页
![](http://s3.51cto.com/wyfs02/M02/72/8D/wKioL1Xmoa2AhP-6AACa8OHkN-U987.jpg)
5.以下是访问tomcat服务器jsp网页
![](http://s3.51cto.com/wyfs02/M00/72/8D/wKioL1XmoeWhV5p1AAGk02R6F6I787.jpg)
相关文章推荐
- oracle之安装
- yum安装lamp+discuz
- linux下的数据备份工具rsync讲解
- zabbix 邮件报警 -- sendmail
- Nginx的反向代理 和 负载均衡
- Nginx 反向代理 Tomcat 传递自定义 Head 问题总结
- Squid
- 什么是反向代理,如何区别反向与正向代理
- 映射公网(花生壳、PubYun、No-IP、DynDNS、Ngrok、Tunnel、localtunnel、pagekite)
- squid缓存服务的搭建和配置管理
- 搭建nginx反向代理用做内网域名转发
- 结合keepalived实现nginx反向代理群集高可用 - 宅鸟乐园 - 51CTO技术博客
- SquidGuard
- 构建squid透明代理网关
- 搭建gerrit服务器(apache&nginx反向代理方式)
- apache+tomcat反向代理
- squid代理服务简单配置
- haproxy反向代理
- Nginx 反向代理 动静分离
- 搭建ATS反向代理服务器压力测试环境