Nginx Reverse Proxy Node.js and Wordpress + Static Files Issue
Posted
by
joemccann
on Server Fault
See other posts from Server Fault
or by joemccann
Published on 2011-08-07T12:24:07Z
Indexed on
2013/11/10
9:59 UTC
Read the original article
Hit count: 248
I have had quite a time trying to get nginx to serve static assets from my wordpress blog. Have a look at the config and let me know if you can help. ( https://gist.github.com/1130332 - to see the entire thing)
server {
listen 80;
server_name subprint.com;
access_log /var/www/subprint/logs/access.log;
error_log /var/www/subprint/logs/error.log;
root /var/www/subprint/server/public; # express serves static resources for subprint.com out of here
location / {
proxy_pass http://127.0.0.1:8124;
root /var/www/subprint/server;
access_log on;
}
#serve static assets
location ~* ^(?!\/).+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
expires max;
access_log off;
}
# the route for the wordpress blog
# unfortunately the static assets (css, img, etc.) are not being pathed/served properly
location /blog {
root /var/www/localhost/public;
index index.php;
access_log /var/www/localhost/logs/access.log;
error_log /var/www/localhost/logs/error.log;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
break;
}
if (!-f $request_filename) {
rewrite /blog$ /blog/index.php last;
break;
}
}
# actually serves the wordpress and subsequently phpmyadmin
location ~* (?!\/blog).+\.php$ {
fastcgi_pass localhost:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/localhost/public$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}
# This works fine, but ONLY with a symlink inside the /var/www/localhost/public directory pointing to /usr/share/phpmyadmin
location /phpmyadmin {
index index.php;
access_log /var/www/phpmyadmin/logs/access.log;
error_log /var/www/phpmyadmin/logs/error.log;
alias /usr/share/phpmyadmin/;
if (!-f $request_filename) {
rewrite /phpmyadmin$ /phpmyadmin/index.php permanent;
break;
}
}
# opt-in to the future
add_header "X-UA-Compatible" "IE=Edge,chrome=1";
}
© Server Fault or respective owner