繁体   English   中英

Nginx / Apache服务静态内容代理

[英]Nginx/Apache Serve Static Content proxy

我需要改善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)?

将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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM