簡體   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