0

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)?

1
  • why do you serve static html file from apache? Commented Mar 30, 2013 at 3:28

1 Answer 1

1

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
}
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the info also to answer the previous question of "why do you serve static html file from apache?" Is because i use joomla and joomla add's the .html class suffix to page url's what is generated by php so i need apache to handle them realy.
Also for some reason my nginx does not want to start with my config like that
That's strange. I can load it in my own devbox. What's the error msg if you run 'nginx -t'? Or what's the error msg in your nginx error log? In linux, the error log is normally /var/log/nginx/error.log.
I just copied/pasted your root directive root c:/websites/www/html; in my answer. However the folder name is a relative path. So nginx will try to load static file from "/etc/nginx/c:/websites/www/html", is it intended?
Well it is a windows server so "c:/" in the hard drive of a windows pc do i have to move the site into the nginx folder what would make it "nginx/websites/www/html;"?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.