I have a website running Nginx and Apache
Apache deals with PHP files, and Nginx the html static files
We have now changed the site so there are no html static files, only PHP files and this has heavy load on the server, so I wanted to put the nginx as a reverse proxy cache, so that the php files coming from Apache will be cached and delivered static...
Can anyone with expertise let me know if the following will work or what I need to change?
...
proxy_cache_path /var/www/cache levels=1:2 keys_zone=my-cache:8m max_size=1000m inactive=600m;
proxy_temp_path /var/www/cache/tmp;
#
# The default server
#
server {
listen 80;
client_max_body_size 100M;
server_name 71.72.73.745 domain.com www.domain.com;
#access_log logs/host.access.log main;
location / {
root /var/www/html/domain;
index index.html index.htm index.php;
location ~* \.(jpg|jpeg|gif|png|ico|js|css)$ {
log_not_found off;
expires 180d;
proxy_pass http://127.0.0.1:8080;
proxy_cache my-cache;
proxy_cache_valid 200 302 60m;
proxy_cache_valid 404 1m;
}
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 = @apache;
# location = /50x.html {
# root /usr/share/nginx/html;
# }
#PHP goes to apache
location ~ \.php$ {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache my-cache;
proxy_cache_valid 200 302 60m;
proxy_cache_valid 404 1m;
}
error_page 404 = @apache;
error_page 405 = @apache;
location @apache {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
...
Please do let me know if the above in my nginx.conf file will work for making all php files taken from Apache to become cached via nginx and delivered as static files, thus reducing server load!
If not, what should i change?
thanks, Aku.