1、nginx和apache的動靜分離配置:
把下面配置放到nginx配置文件相應的server { }裏面,如果使用其他端口號,改一下就行:
#所有php的動態頁面均交由apache處理
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://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)$
{ expires 15d; }
location ~ .*\.(js|css)?$
{ expires 1h; }
如果之前設置了FastCGI的,把下面的配置註釋掉:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root /var/www/html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# include fastcgi.conf;
#}
重啓nginx就生效,如圖所示,標頭顯示nginx,phpinfo裏面顯示是apache,說明動靜分離生效。
2、nginx和tomcat、resin的動靜分離配置:
同上,把下面配置放到nginx配置文件相應的server { }裏面:
#所有jsp的頁面均交由tomcat或resin處理
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://127.0.0.1:8080;
}
#所有靜態文件由nginx直接讀取不經過resin
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; }
更多的nginx配置和模塊詳解請參考官方wiki:http://wiki.nginx.org/Main