# Disable CDN causes old images with CDN URL can not be shown

**URL:** https://meta.discourse.org/t/disable-cdn-causes-old-images-with-cdn-url-can-not-be-shown/29657
**Category:** Support
**Created:** [4 juni 2015 om 16:25 UTC](https://meta.discourse.org/t/disable-cdn-causes-old-images-with-cdn-url-can-not-be-shown/29657 "2015-06-04T16:25:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![trandatnh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/trandatnh/32/115055_2.png) [@trandatnh](https://meta.discourse.org/u/trandatnh)
#### Post date: [4 juni 2015 om 16:25 UTC](https://meta.discourse.org/t/disable-cdn-causes-old-images-with-cdn-url-can-not-be-shown/29657/1 "2015-06-04T16:25:37Z")

</div>

I’ve just disabled CDN to save the cost. However, all the old images, which is uploaded while I was using cloudfront, are failed to load.

For example:

I have CDN URL is `cdn.mydomain.com`. After disabling CDN, the `cdn.mydomain.com` is invalid so that all the images should start with `mydomain.com` instead.

**Is there anyway to convert all those urls programmatically?**

* * *

Note: I am going to use S3 to store all my images. Can I just make use of this opportunity to convert everything from cdn to s3 url?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [4 juni 2015 om 16:33 UTC](https://meta.discourse.org/t/disable-cdn-causes-old-images-with-cdn-url-can-not-be-shown/29657/2 "2015-06-04T16:33:22Z")

</div>

> [@trandatnh](#):
>
> Is there anyway to convert all those urls programmatically?

You will need to rebake all your post to update the urls. There are 2 ways of doing it:

The low-CPU usage but _slow_ way

```plaintext
# ssh into server
cd /var/discourse
./launcher enter app
rails c
Post.update_all(baked_version: nil)

```

The high-CPU usage but faster way

```plaintext
# ssh into server
cd /var/discourse
./launcher enter app
rake posts:rebake

```

---

<div class="post-metadata">

### Author: ![trandatnh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/trandatnh/32/115055_2.png) [@trandatnh](https://meta.discourse.org/u/trandatnh)
#### Post date: [4 juni 2015 om 16:36 UTC](https://meta.discourse.org/t/disable-cdn-causes-old-images-with-cdn-url-can-not-be-shown/29657/3 "2015-06-04T16:36:05Z")

</div>

I tried your post here

[https://meta.discourse.org/t/disabled-cdn-emoji-picture-url-error/20878/2?u=trandatnh](https://meta.discourse.org/t/disabled-cdn-emoji-picture-url-error/20878/2)

But I received this error:

```plaintext
rake posts:rebake
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)

(See full trace by running task with --trace)

```

I think it is because the answer was very old.

I added `--trace`

```plaintext
root@daynhauhoc:/var/discourse# rake posts:rebake --trace
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/usr/lib/ruby/vendor_ruby/rake/application.rb:584:in `raw_load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:89:in `block in load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:160:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:88:in `load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:72:in `block in run'
/usr/lib/ruby/vendor_ruby/rake/application.rb:160:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:70:in `run'
/usr/bin/rake:27:in `<main>'

```

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [4 juni 2015 om 16:38 UTC](https://meta.discourse.org/t/disable-cdn-causes-old-images-with-cdn-url-can-not-be-shown/29657/4 "2015-06-04T16:38:43Z")

</div>

You need to run that command from **inside** the container (via `./launcher enter app`)

---

<div class="post-metadata">

### Author: ![trandatnh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/trandatnh/32/115055_2.png) [@trandatnh](https://meta.discourse.org/u/trandatnh)
#### Post date: [4 juni 2015 om 16:40 UTC](https://meta.discourse.org/t/disable-cdn-causes-old-images-with-cdn-url-can-not-be-shown/29657/5 "2015-06-04T16:40:52Z")

</div>

I ran the command but I got this error

```plaintext
root@daynhauhoc:/var/discourse# ./launcher enter app
Error: Command not found: exec
Error: Command not found: -it
Usage: docker [OPTIONS] COMMAND [arg...]

```

I am using `v1.4.0.beta1 +4`. I used to be able to `rake` last time when I migrated from S3 to local. I think docker is ~~up to date~~ outdated.

```plaintext
root@daynhauhoc:/var/discourse# git pull
Already up-to-date.
root@daynhauhoc:/var/discourse# ./launcher rebuild app
Ensuring discourse docker is up to date
Fetching origin
Discourse Docker is up-to-date

```

I’ve just temporary upgraded Digital Ocean droplet to higher plan using flexible resize feature because I think the rake will take a lot of CPU usage. ~~But I don’t think resizing the droplet causes any issue with docker.~~

I am using docker 1.2

```plaintext
root@daynhauhoc:/var/discourse# docker -v
Docker version 1.2.0, build fa7b24f

```

Upgraded to 1.6

```plaintext
apt-get install lxc-docker
root@daynhauhoc:/var# docker -v
Docker version 1.6.2, build 7c8fca2

```

* * *

**Update 1** Successfully enter app and raking

```plaintext
root@daynhauhoc:/# rake posts:rebake
Rebaking post markdown for 'default'
      943 / 35451 ( 2.7%)

```

**Update 2** All the images are OK now. Thank @zogstrip 👍

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [5 juni 2015 om 15:04 UTC](https://meta.discourse.org/t/disable-cdn-causes-old-images-with-cdn-url-can-not-be-shown/29657/6 "2015-06-05T15:04:08Z")

</div>


