2012年10月12日 星期五

Nginx搭配Apache做balance與proxy與避免ip直接訪問

#所有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; }
ref: (http://www.ha97.com/5119.html)

一些觀念
ref : (http://www.itlearner.com/article/4508)

實作補充
ref : (http://stackoverflow.com/questions/3434182/apache-and-ultimate-config-for-nginx-to-serve-all-virtual-hosts-in-the-right-way)

//避免直接ip訪問
在nginx/conf.d/default.conf裡加上並寫上自己對應的rewrite rule ex:http://yourdomain.com$request_uri?


server {
        listen 80 default_server;#ip
        server_name ip;
        rewrite ^ http://mrshih.com$request_uri?;
}