W3, Apache, nginx and minimize
-
First, I would like to say that W3 seems like a great program.
When I first tried to minimize js and css, I was getting 404s. It worked fine when I unchecked the “Rewrite URL structure”. Then I realized that it’s using the .htaccess file to create the css and js if they are not there, quite clever. Since I don’t allow overrides on my server because it’s too slow, I needed to place the code directly into the virtual host of the httpd.conf file.
<Directory "/your-root/htdocs/wp-content/cache/minify"> RewriteEngine On RewriteBase /wp-content/cache/minify/ RewriteRule /w3tc_rewrite_test$ ../../plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 [L] RewriteCond %{HTTP:Accept-Encoding} gzip RewriteRule .* - [E=APPEND_EXT:.gzip] RewriteCond %{REQUEST_FILENAME}%{ENV:APPEND_EXT} -f RewriteRule (.*) $1%{ENV:APPEND_EXT} [L] RewriteRule ^(.+/[X]+\.css)$ ../../plugins/w3-total-cache/pub/minify.php?test_file=$1 [L] RewriteRule ^(.+\.(css|js))$ ../../plugins/w3-total-cache/pub/minify.php?file=$1 [L] </Directory>That still didn’t work because nginx is set up to process static js and css files, so it never made it to apache. After fussing around with nginx and searching for solutions, I finally arrived at this.
location ~* ^.+.(jpg|png|gif|js|css|pdf|flv|swf|ico|txt|cur)$ { try_files $uri @apachesite; gzip on; gzip_static on; access_log off; expires 1y; } location / { access_log off; add_header Server Apache/2; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://xxx.xxx.x.xx:80; } location @apachesite{ access_log off; add_header Server Apache/2; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://xxx.xxx.x.xx:80; }Now if the file does not exist it passes off to Apache and Apache will run the minify.php file and create the css and js files. Hope this helps someone with their configuration.
Craig
The topic ‘W3, Apache, nginx and minimize’ is closed to new replies.