Welcome! Log In Create A New Profile

Advanced

Help with WordPress Nginx static proxy cache

Posted by c3mdigital 
Help with WordPress Nginx static proxy cache
October 04, 2010 02:24AM
Hello All,

I currently have Nginx running as a reverse static proxy cache passing PHP to Apache. Everything seems to be working fine but for some reason I am getting an "X-Powered-By:" header from my .htaccess file added to the headers of static files which should be handled by Nginx.

Here are the Response Headers:


[code]
HTTP/1.1 200 OK
Server: nginx/0.7.65
Date: Mon, 27 Sep 2010 15:47:22 GMT
Content-Type: text/css; charset=utf-8
Connection: keep-alive
[color=#FF0000]X-Powered-By: W3 Total Cache/0.9.1.3[/color]
Pragma: public
Expires: Fri, 26 Nov 2010 15:47:22 GMT
Vary: Accept-Encoding,User-Agent
Last-Modified: Sat, 25 Sep 2010 23:08:59 GMT
ETag: "pub1285456139;gz"
Cache-Control: max-age=5184000, public, must-revalidate, proxy-revalidate
Content-Length: 5038
Content-Encoding: gzip
[/code]

I am running Debian Lenny with Apache2 and Nginx 0.7.65 with 3 WordPress sites on a VPS server with 1 IP address. It's running very fast, I get 1833.56 requests per second on Apache bench with -n 1000 -c 20 on my home page.

I would appreciate it if someone could look at my server files and let me know if I am doing anything wrong.

In httpd.conf I have KeepAlive off and mod_rpaf installed.
ports.conf:
[code]
NameVirtualHost *:8080
Listen 8080
[/code]

In each site Vhost:
[code]
<VirtualHost 127.0.0.1:8080>
ServerAdmin info@yoursite.com
ServerName yoursite.com
ServerAlias www.yoursite.com
DocumentRoot /srv/www/yoursite.com/public_html/
ErrorLog /srv/www/yoursite.com/logs/error.log
CustomLog /srv/www/yoursite.com/logs/access.log combined
</VirtualHost>
[/code]

Nginx.conf:
[code]
user www-data;
worker_processes 4;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

access_log /var/log/nginx/access.log;
client_body_temp_path /var/lib/nginx/body 1 2;
gzip_buffers 32 8k;
sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_comp_level 6;
gzip_http_version 1.0;
gzip_min_length 0;
gzip_types text/html text/css image/x-icon
application/x-javascript application/javascript text/javascript application/atom+xml application/xml ;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
[/code]

/etc/nginx/sites-enabled/default.conf:

[code]
proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=staticfilecache:180m max_size=500m;
proxy_temp_path /var/lib/nginx/proxy;
proxy_connect_timeout 30;
proxy_read_timeout 120;
proxy_send_timeout 120;

#IMPORTANT - this sets the basic cache key that's used in the static file cache.
proxy_cache_key "$scheme://$host$request_uri";

upstream wordpressapache {
#The upstream apache server. You can have many of these and weight them accordingly,
#allowing nginx to function as a caching load balancer
server 127.0.0.1:8080 weight=1 fail_timeout=120s;
}
[/code]

Per WordPress site: /etc/nginx/sites-enabled/yourdomain.conf

[code]
server {
#Only cache 200 responses, and for a default of 20 minutes.
proxy_cache_valid 200 20m;

#Listen to your public IP
listen 80;

#Probably not needed, as the proxy will pass back the host in "proxy_set_header"
server_name www.yoursite.com yoursite.com;
access_log /var/log/nginx/yoursite.proxied.log;

# "combined" matches apache's concept of "combined". Neat.
access_log /var/log/apache2/nginx-access.log combined;
# Set the real IP.
proxy_set_header X-Real-IP $remote_addr;

# Set the hostname
proxy_set_header Host $host;

#Set the forwarded-for header.
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

location / {
# If logged in, don't cache.
if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $do_not_cache 1;
}
proxy_cache_key "$scheme://$host$request_uri $do_not_cache";
proxy_cache staticfilecache;
proxy_pass http://wordpressapache;
}

location ~* wp\-.*\.php|wp\-admin {
# Don't static file cache admin-looking things.
proxy_pass http://wordpressapache;
}

location ~* \.(jpg|png|gif|jpeg|css|js|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx)$ {
# Cache static-looking files for 120 minutes, setting a 10 day expiry time in the HTTP header,
# whether logged in or not (may be too heavy-handed).
proxy_cache_valid 200 120m;
expires 864000;
proxy_pass http://wordpressapache;
proxy_cache staticfilecache;
}

location ~* \/[^\/]+\/(feed|\.xml)\/? {
# Cache RSS looking feeds for 45 minutes unless logged in.
if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $do_not_cache 1;
}
proxy_cache_key "$scheme://$host$request_uri $do_not_cache";
proxy_cache_valid 200 45m;
proxy_cache staticfilecache;
proxy_pass http://wordpressapache;
}

location = /50x.html {
root /var/www/nginx-default;
}

# No access to .htaccess files.
location ~ /\.ht {
deny all;
}

}
[/code]
I am using normal WordPress .htaccess rewrite rules along with APC and page caching with W3 Total Cache. Thanks in advance for any advice.



Edited 1 time(s). Last edit at 10/04/2010 02:24AM by c3mdigital.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 122
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready