Images upload but aren't displaying - Multisite + Nginx


#1

I have Nginx set up as a reverse proxy on my VPS. I also have a WordPress multisite installation set up. Everything works just fine except for the uploaded images. I can create new sites and I can upload images to those site but the images don't display in the backend or on the frontend.

Here is my Nginx config for the multisite installation:

map $http_host $blogid {  
    default   -999;  
    include /home/cpress/public_html/wp-content/plugins/nginx-helper/map.conf;  
}  

server {  
          error_log /var/log/nginx/vhost-error_log warn;  
          listen 204.197.248.70:80;  
          server_name churchpr.es www.churchpr.es *.churchpr.es;  
          access_log /usr/local/apache/domlogs/churchpr.es-bytes_log bytes_log;  
          access_log /usr/local/apache/domlogs/churchpr.es combined;  
          root /home/cpress/public_html;  
          index index.php index.html index.htm;  

          location / {  
          location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {  
          expires 30d;  
          try_files $uri  $uri/ /index.php?$args;  
          }  

          rewrite /wp-admin$ $scheme://$host$uri/ permanent;  


          error_page 405 = @backend;  
          add_header X-Cache "HIT from Backend";  
          proxy_pass http://204.197.248.70:8081;  
          include proxy.inc;  
          }  
          location @backend {  
          internal;  
          proxy_pass http://204.197.248.70:8081;  
          include proxy.inc;  
          }  
          location ~ .*\.(php|jsp|cgi|pl|py)?$ {  
          proxy_pass http://204.197.248.70:8081;  
          include proxy.inc;  
          }  
          location ~ /\.ht {  
          deny all;  
          }  

location ~ \.php$ {  
          try_files $uri @wordpress;  
          proxy_set_header Host $host;  
          proxy_set_header X-Real-IP $remote_addr;  
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
          proxy_pass   http://204.197.248.70:8081;  
          }  

location ~ ^/files/(.*)$ {  
          try_files /wp-content/blogs.dir/$blogid/ $uri/wp-includes/ms-files.php?file=$1;  
          access_log off; log_not_found off; expires max;  
          }  

location ^~ /blogs.dir {  
          internal;  
          alias /home/cpress/public_html/wp-content/blogs.dir;  
          access_log off; log_not_found off;    expires max;  
          }  
}  

#2

Sorry for delayed reply.

We generally do not use or recommend using Nginx & Apache together.

Anyway, you can try commenting out following line:

  
include /home/cpress/public_html/wp-content/plugins/nginx-helper/map.conf;
  

If that doesn’t work, try using Nginx with PHP5-FPM directly rather than getting Apache involved.


#3

hi i have the same problem, but i’m running on wp 3.5.2 and i see that 3.6 has the same problem, i have use your configuration, but i don’ha ve proxy.inc, which is the setting of proxy.inc that you have include in your configuration?

thx

J.


#4

@jacopolaporta

Please share WordPress site URL on which images are broken.

Also, let me know which config you are using from table on this page - http://rtcamp.com/wordpress-nginx/tutorials


#5

Hi Rahul now i have set this nginx.conf

ap $http_host $blogid {
default -999;
include /var/www/vhosts/builtinsite.com/httpdocs/wp-content/uploads/nginx-helper/map.conf;
}

server {
error_log /var/log/nginx/vhost-error_log warn;
listen 205.186.160.61:80;
server_name builtinsite.com *.builtinsite.com;
# access_log /usr/local/apache/domlogs/churchpr.es-bytes_log bytes_log;
# access_log /usr/local/apache/domlogs/churchpr.es combined;
root /var/www/vhosts/builtinsite.com/httpdocs;
index index.php index.html index.htm;

      location / {  
      location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {  
      expires 30d;  
      try_files $uri  $uri/ /index.php?$args;  
      }  

      rewrite /wp-admin$ $scheme://$host$uri/ permanent;  


      error_page 405 = @backend;  
      add_header X-Cache "HIT from Backend";  
      proxy_pass http://205.186.160.61:7081;  
      include /var/www/vhosts/builtinsite.com/conf/proxy.conf;  
      }  
      location @backend {  
      internal;  
      proxy_pass http://205.186.160.61:7081;  
      include /var/www/vhosts/builtinsite.com/conf/proxy.conf;  
      }  
      location ~ .*\.(php|jsp|cgi|pl|py)?$ {  
      proxy_pass http://205.186.160.61:7081;  
      include /var/www/vhosts/builtinsite.com/conf/proxy.conf;  
      }  
      location ~ /\.ht {  
      deny all;  
      }  

location ~ .php$ {
try_files $uri @wordpress;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://205.186.160.61:7081;
}

location ~ ^/files/(.*)$ {
try_files /wp-content/uploads/sites/$blogid/ $uri/wp-includes/ms-files.php?file=$1;
access_log off; log_not_found off; expires max;
}

location ^~ /sites {
internal;
alias /var/www/vhosts/builtinsite.com/httpdocs/wp-content/uploads/sites;
access_log off; log_not_found off; expires max;
}

    }  

my proxy.conf is:

proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

now i obtain 400 bad request

builtinsite.com and subdomain for example

http://templateblog.builtinsite.com

if you want i can back to empty ngix.conf, i have plesk 11.0.9 installed


#6

Rahul i have wp 3.6 mu installed and i don’t have blogdir. :frowning:

my .htaccess is the std wp mu

BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

add a trailing slash to /wp-admin

RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).) $1 [L]
RewriteRule ^(.
.php)$ $1 [L]
RewriteRule . index.php [L]

END WordPress


#7

Rahul now i resume what i do:

i have installed wp 3.6 on my centos 5.8 with nginx reverse proxy and plesk 11.0.9

i set up subdomains and doesn’t work for a plesk issue that i solved in this way:

"
Add a single line - ServerAlias “*.yourdomain.com” - to the start of the file.
Do not add the or headers - just add the server alias command and wildcard domain name on a single line as shown above.

Author’s note - On my install, being a belt and braces type of guy, I also added these lines (without line numbers) after the ServerAlias line -

<Directory /var/www/vhosts/mydomain.com/>
AllowOverride FileInfo Options

Save the vhost.conf file and restart Apache again. "

after that and setting cname on godaddy the wildcard subdomain subdomain works.

the problem is when you create a new blog the new blog doesn’t load correctly the themes and if you upload an image you have the image with question mark and the link is broken

you can take a look here

getting 404 nginx

to have my nginx.conf i have create a custom template plesk of nginxvirtualhost.php where i add only this code as plesk suggest

<?php if (file_exists($VAR->domain->physicalHosting->vhostDir . '/conf/nginx.conf')): ?>
include <?php echo $VAR->domain->physicalHosting->vhostDir;?>/conf/nginx.conf;  
<?php endif ?>

so now in my var/www/vhosts/builtinsite.com/conf i have nginx.conf, proxy.conf and vhost.conf

the default nginx.conf configuration is in etc/nginx/conf and is this:

#user nginx;
worker_processes 1;

#error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;

#pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

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

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
#                  '$status $body_bytes_sent "$http_referer" '  
#                  '"$http_user_agent" "$http_x_forwarded_for"';  

#access_log  /var/log/nginx/access.log  main;  

sendfile        on;  
#tcp_nopush     on;  

#keepalive_timeout  0;  
keepalive_timeout  65;  
#tcp_nodelay        on;  

#gzip  on;  
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";  

server_tokens off;  

#inizio codice di reconf;

include /etc/nginx/conf.d/*.conf;

}

thats it i hope that you can help me

J.


#8

this is a piece of error log :

2013/08/07 13:27:49 [emerg] 26434#0: host not found in upstream “.builtinsite.com" in /var/www/vhosts/builtinsite.com/conf/nginx.conf:8
2013/08/07 13:28:40 [warn] 26554#0: conflicting server name “builtinsite.com” on 0.0.0.0:80, ignored
2013/08/07 13:28:40 [warn] 26554#0: conflicting server name "
.builtinsite.com” on 0.0.0.0:80, ignored
2013/08/07 13:28:40 [warn] 26559#0: conflicting server name “builtinsite.com” on 0.0.0.0:80, ignored
2013/08/07 13:28:40 [warn] 26559#0: conflicting server name “.builtinsite.com" on 0.0.0.0:80, ignored
2013/08/07 13:28:40 [warn] 26564#0: conflicting server name “builtinsite.com” on 0.0.0.0:80, ignored
2013/08/07 13:28:40 [warn] 26564#0: conflicting server name "
.builtinsite.com” on 0.0.0.0:80, ignored
2013/08/07 13:28:49 [error] 26566#0: *1 open() “/var/www/vhosts/avusy.com/httpsdocs/wp-content/uploads/sites/2/2013/08/psd-clipboard-icon.png” failed (2: No such file or directory), client: 2.235.76.102, server: avusy.com, request: “GET /wp-content/uploads/sites/2/2013/08/psd-clipboard-icon.png HTTP/1.1”, upstream: “http://205.186.160.61:7080/wp-content/uploads/sites/2/2013/08/psd-clipboard-icon.png”, host: “templateblog.builtinsite.com
2013/08/07 13:28:51 [error] 26566#0: *1 open() “/var/www/vhosts/avusy.com/httpsdocs/wp-content/uploads/sites/2/2013/08/psd-clipboard-icon.png” failed (2: No such file or directory), client: 2.235.76.102, server: avusy.com, request: “GET /wp-content/uploads/sites/2/2013/08/psd-clipboard-icon.png HTTP/1.1”, upstream: “http://205.186.160.61:7080/wp-content/uploads/sites/2/2013/08/psd-clipboard-icon.png”, host: “templateblog.builtinsite.com

2013/08/07 13:05:44 [error] 26059#0: *3 open() “/var/www/vhosts/avusy.com/httpsdocs/wp-content/themes/twentythirteen/js/functions.js” failed (2: No such file or directory), client: 2.235.76.102, server: avusy.com, request: “GET /wp-content/themes/twentythirteen/js/functions.js?ver=2013-07-18 HTTP/1.1”, upstream: “http://205.186.160.61:7080/wp-content/themes/twentythirteen/js/functions.js?ver=2013-07-18”, host: “templateblog.builtinsite.com”, referrer: “http://templateblog.builtinsite.com/

as you know nginx point always in wrong domain, avusy.com is domain that i have registered when buy the server anyway in plesk the 2 domains have different webspaces.


#9

ok done, the port was 7080 not 7081.

thx again

J.


#10

Sorry but we do not provide support for Apache.

You are not following our tutorials entirely. Apache is not needed to run WordPress with Nginx.

In case you wish to throw apache and have a clean setup, check this - http://rtcamp.com/wordpress-nginx/tutorials/linux/ubuntu-php-apc-mysql-postfix/


#11