Nginx / Apache服务静态内容代理

时间:2013-03-30 01:11:32

标签: apache static nginx

我需要帮助改进nginx模式匹配正则表达式。

# serve static files from nginx
location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|pdf|ppt|txt|tar|wav|bmp|rtf|js|mp3|avi|mov|flv|swf)$ {
root c:/websites/www/html;
expires 1y;
}


# pass requests for dynamic content to apache listening on 8080
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 128m;
client_body_buffer_size 256k;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 32 256k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
}

Apache在端口8080上运行,nginx在端口80上运行。用于处理的唯一Apache是​​HTML,PHP和基本的脚本处理。 nginx服务于其他一切。

由于我不是正则表达式的大师并且对nginx很新,我怎样才能使我的模式匹配更友好?有没有办法定义我希望Apache处理和服务的脚本(html,php)?

1 个答案:

答案 0 :(得分:1)

将php / html请求传递给apache更容易,然后让nginx处理剩下的事情:

# serve all remaining static file requests from nginx
location / {
  root c:/websites/www/html;
  expires 1y;
}

# pass any request uri ending with .php or .html, .htm to apache
location ~* \.(php|html|htm)$ {
  # proxy to apache
}