Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 to change? Help much appreciated...

thanks, Aku.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.