nginx+apache动静分离

nginx+apache动静分离

浏览次数:
信息来源: 用户投稿
更新日期: 2025-12-04 11:29:35
文章简介

1、nginx和apache的动静分离配置:把下面配置放到nginx配置文件相应的server{}里面,如果使用其他端口号,改一下就行:#所有php的动态页面均交由apache处理 proxy

2025阿里云双十一服务器活动

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

nginx+apache动静分离

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的动静分离怎么配置的详细内容,更多请关注主机测评网其它相关文章!

标签:
如何进行SQL数据库的容灾和灾难恢复(数据库灾难恢复方案)
« 上一篇
返回列表
下一篇 »

如本文对您有帮助,就请抽根烟吧!