C0nw0nk
C0nw0nk

Reputation: 383

Nginx/Apache Serve Static Content proxy

I need help with improving a nginx pattern matching regex.

# 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 runs on port 8080 and nginx runs on port 80. The only thing Apache is being used for handling is HTML, PHP and basically script processing. nginx serves everything else.

Since I am no guru with regex and am very new to nginx, how can I make my pattern matching more friendly? Is there a way to define the scripts I want Apache to handle and serve (html,php)?

Upvotes: 0

Views: 1737

Answers (1)

Chuan Ma
Chuan Ma

Reputation: 9914

It's easier to pass php/html requests to apache and then let nginx handle the rest:

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

Upvotes: 1

Related Questions