1、nginx和apache的动静分离配置:
把下面配置放到nginx配置文件相应的server{}里面,如果使用其他端口号,改一下就行:
#所有php的动态页面均交由apache处理
proxy_set_headerhost$host;
proxy_set_headerx-real-ip$remote_addr;
proxy_set_headerx-forwarded-for$proxy_add_x_forwarded_for;
proxy_passhttp://127.0.0.1:88;
}
#所有静态文件由nginx直接读取不经过apache
location~.*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{expires1h;}
如果之前设置了fastcgi的,把下面的配置注释掉:
#passthephpscriptstofastcgiserverlisteningon127.0.0.1:9000
#fastcgi_pass127.0.0.1:9000;
[root@localhost~]#vi/usr/local/nginx/conf/nginx.conf
usernginx;
default_typeapplication/octet-stream;
log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent""$http_x_forwarded_for"';
access_loglogs/access.logmain;
gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;
#jsp网站程序根目录,一般nginx与tomcat在同一个目录
root/usr/local/tomcat/webapps/root;
indexindex.htmlindex.jspindex.html;
proxy_passhttp://127.0.0.1:8080;#来自jsp请求交给tomcat处理
proxy_set_headerhost$host;#后端的web服务器可以通过x-forwarded-for获取用户真实ip

proxy_set_headerx-forwarded-for$proxy_add_x_forwarded_for;
client_max_body_size10m;#允许客户端请求的最大单文件字节数
client_body_buffer_size128k;#缓冲区代理缓冲用户端请求的最大字节数
proxy_connect_timeout90;#nginx跟后端服务器连接超时时间(代理连接超时)
proxy_read_timeout90;#连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size4k;#设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers632k;#proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size64k;#高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size64k;#设定缓存文件夹大小,大于这个值,将从upstream服务器传
location~.*\.(gif|jpg|png|bmp|swf)$#由nginx处理静态页面
expires30d;#使用expires缓存模块,缓存到客户端30天
location~.*\.(jsp|js|css)?$
error_page404/404.html;#错误页面
error_page500502503504/50x.html;
}
vi/etc/init.d/nginx
#!/bin/bash
#description:nginxservicecontrolscript
prog="/usr/local/nginx/sbin/nginx"
pidf="/usr/local/nginx/logs/nginx.pid"
echo"nginxservicestartsuccess."
echo"nginxservicestopsuccess."
echo"reloadnginxconfigsuccess."
echo"usage:$0{start|stop|restart|reload}"
esac
[root@localhost~]#chmod+x/etc/init.d/nginx
[root@localhost~]#servicenginxrestart
[root@localhost~]#chkconfig--addnginx
[root@localhost~]#chkconfignginxon
以上就是Nginx配合Apache或Tomcat的动静分离怎么配置的详细内容,更多请关注主机测评网其它相关文章!
本文来源:虚拟主机--nginx+apache动静分离
本文地址:https://www.idcbaba.com/zhuji/2021.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 1919100645@qq.com 举报,一经查实,本站将立刻删除。



