nginx代理apache和tomcat
原创
©著作权归作者所有:来自51CTO博客作者xinfan0507的原创作品,请联系作者获取转载授权,否则将追究法律责任
1、系统环境
装有apache,是www.xx.com的web容器
装有tomcat,是yh.xx.com:81的web容器
然后安装nginx代理,使得他们都是80端口访问
2、wget http://down1.chinaunix.net/distfiles/nginx-1.0.8.tar.gz
安装nginx之前要安装pcre
yum -y install pcre-devel
3、解压,配置,编译,安装
./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_stub_status_module
make && make install
4、安装后开始修改配置文件
Nginx与Apache、Tomcat、Resin动静分离核心配置
参考网址:http://www.ha97.com/5119.html
增加如下配置
server {
listen 8080;
server_name www.xx.com; #绑定域名
index index.htm index.html index.php; #默认文件
root /opt/apache2/htdocs/; #网站根目录
location ~ .(php)?$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://www.xx.com:82;
}
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{ expires 15d; }
location ~ .*.(js|css)?$
{ expires 1h; }
}
server {
listen 80;
server_name yh.xx.com; #绑定域名
index index.htm index.html index.jsp; #默认文件
root /opt/tomcat/youhui_webapps/; #网站根目录
# include location.conf; #调用其他规则,也可去除
location ~ .(jsp|jspx|do)?$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://yh.xx.com:81;
}
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{ expires 15d; }
location ~ .*.(js|css)?$
{ expires 1h; }
}
}
6、然后可以通过www.xx.com 和yh.xx.com来访问不同的网站
下一篇:mysql-5.5.31主从复制
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Nginx代理tomcat
tomcat
tomcat -
apache和nginx设置反向代理
title: apache和nginx设置反...
apache nginx 重启 配置文件 ubuntu -
nginx代理tomcat配置
server{ listen 80; server_name java.test.com; &
nginx代理tomcat配置 -
nginx 配置tomcat代理
server {
nginx linux html php Apache