0

我需要帮助来改进 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)?

4

1 回答 1

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
}
于 2013-03-30T03:49:38.697 回答