Ubuntu: 14.04

Wordpress: 3.8.2

I'm migrating an old website to a fresh setup using wordpress front-ended with nginx. It's mostly gone fine, including creating a custom theme, but when I upload images they will only show as broken links.

The upload process itself seems to work. I checked the location on the file system and the files are there in all their different sizes. If I go into "Edit Image" for the uploaded image, I can see it, but every other location in wordpress admin and the main website shows a broken link.

Here is proof that the files are successfully uploading through wp-admin:

root@[hostname]:/srv/www/wp-content/[hostname]/uploads/2014/11# ls -al
total 284
drwxrwxr-- 2 www-data www-data   4096 Nov  8 01:12 .
drwxrwxr-- 3 www-data www-data   4096 Nov  8 01:03 ..
-rw-rw-r-- 1 www-data www-data  10450 Nov  8 01:03 SJB_0227-150x150.jpg
-rw-rw-r-- 1 www-data www-data  20732 Nov  8 01:03 SJB_0227-199x300.jpg
-rw-rw-r-- 1 www-data www-data  89325 Nov  8 01:03 SJB_0227.jpg
-rw-rw-r-- 1 www-data www-data  10069 Nov  8 01:12 SJB_0229-150x150.jpg
-rw-rw-r-- 1 www-data www-data  22616 Nov  8 01:12 SJB_0229-300x199.jpg
-rw-rw-r-- 1 www-data www-data 118579 Nov  8 01:12 SJB_0229.jpg

My /etc/wordpress/config-[hostname].php includes:

define('WP_CONTENT_DIR', '/srv/www/wp-content/[hostname]');

The relevant part of my nginx config:

root /var/www/html/wordpress;
        index index.php;
        server_name [hostname];

        location / {
                try_files $uri $uri/ /index.php?$args;

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                include fastcgi_params;

I should note that ubuntu automatically created a full /var/www/html/wordpress/wp-content directory, although I'm not sure what that is used for as the files uploaded through wp-admin show up in WP_CONTENT_DIR defined above.

On my main website the links do not work, and are formed like:


Everything except for viewing images works fine with the website. What am I missing?


I have a solution below. I should also note that the /var/www/html/wordpress path above was actually a symlink to /usr/share/wordpress that I had created and forgot about. However the issue persisted when it was changed to the actual location.

  • As a test I copied one of the JPGs to the root of the website to verify that nginx was willing to display JPGs in general. It displayed fine when directly accessed like that. – Neobyte Nov 8 '14 at 3:06
  • Defining WP_CONTENT_DIR in wordpress config does not tell nginx that it should serve http://[hostname]/wp-content/ from there (outside your root folder). You need to map /wp-content/ to the correct location by either symlinking (like you mentioned in your answer) or by other means. – Ketola Nov 8 '14 at 8:53

It appears that the Ubuntu install is NOT honouring the WP_CONTENT_DIR settings in /etc/wordpress/config-[hostname].php.

I resolved the issue (at least for now) with:

cd /usr/share/wordpress/wp-content
mv uploads uploads-old
ln -s /my/correct/upload/directory uploads

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.