這個[模塊][1]的使用方法和fastcgi模塊很相似.
## 配置示例 [參考][2] [參考][3]
~~~bash
http{
proxy_temp_path path /tmp/nginx_temp_cache 1 2
proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=nginx_cache:10m;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 64k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_intercept_errors on;
server{
...
location /url/ {
proxy_pass remote_php_ip/new/url
proxy_cache nginx_cache;
proxy_cache_valid 200 302 1m;
proxy_cache_valid 404 1m;
proxy_set_header X-Cache "$upstream_cache_status From $host";
}
...
}
}
~~~
>[info]upstream_cache_status
## 常用參數
~~~
proxy_pass http://{SERVER_IP|UPSTREAM_NAME}/uri
proxy_cache_path path [levels=levels] keys_zone=name:size [inactive=time] [max_size=size] ;
proxy_cache zone_name;
proxy_cache_valid [code] time;
proxy_cache_method GET|HEAD
proxy_cache_use_stale error timeout ...
proxy_cache_min_uses 1;
proxy_cache_bypass string: 設置在何種情形下nginx將不從cache取數據的;
$cookie_nocache $arg_nocache $http_authorization
proxy_set_header X-Cache $upstream_cache_status
~~~
>[danger] 注意
~~~
location /forume/ {
proxy_pass http://192.168.8.30/bbs/;
}
http://192.168.8.30/forum/ --> http://192.168.8.30/bbs/
或者,使用正則匹配時,比較特殊,ip后邊不能跟url,此處直接映射為http://192.168.8.30/forume/
location ~* ^/forume/ {
proxy_pass http://192.168.8.30;
}
http://192.168.8.30/forum/ --> http://192.168.8.30/forum/
~~~
[1]:http://nginx.org/en/docs/http/ngx_http_proxy_module.html
[2]:https://zhangge.net/5067.html
[3]:https://zhangge.net/5042.html
- nginx的功能
- nginx常用變量
- Nginx內核模塊
- Nginx的事件模塊
- Nginx的HTTP模塊
- Nginx的fastcgi
- nginx的proxy
- Upstream實現后臺服務器集群
- 文件操作優化相關的配置
- Nginx模塊管理和進程管理
- 模塊管理
- 進程管理
- 針對Nginx的Linux系統優化
- Nginx如何處理一個請求
- nginx狀態信息
- Nginx工具
- Nginx限制流量
- Nginx限制用戶的并發連接數
- 配置FLV服務器
- Nginx訪問控制
- Nginx自動索引
- Nginx網頁壓縮傳輸
- 控制Nginx如何記錄日志
- Nginx改寫響應
- Nginx重寫
- 后臺Nginx記錄原始原始IP
- Nginx防盜鏈
- Nginx的https