5

I'm using AppFog PaaS system for a few days, and I love it, It's probably the best PaaS system that I've tested (I've used other 3 ones previously), but didn't find information about how to serve static content with the Web server in frontend (Apache https or nginx) I'm not sure what server is being used.

My app is a Python WSGI with CherryPy and works perfectly in AppFog but I don't wan't CherryPy to serve static content, I think that Apache httpd or nginx is a better option for that.

Roberto
  • 8,586
  • 3
  • 42
  • 53
  • I think that I'm wrong and AppFog use nginx as Proxy server instead Apache httpd for Python apps, anyway, I'm still need to configure direct access to static content. – Roberto Nov 03 '12 at 16:18
  • If my answer was helpful please set it as your solution. Thanks! – Andrew Kloos Nov 04 '12 at 13:41

2 Answers2

2

With Ryan's support, I'm finally able to load static files! Here are the steps:

  1. Created a 'static' directory in the project root - here all static files will be collected running the collectstatic command.

  2. Edit the settings.py file:

    STATIC_ROOT = os.path.join( os.path.abspath( os.path.dirname(file) ), '../static' ) # May change depending on where your settings.py file is!

    STATIC_URL = '/static/'

  3. Add following line in urlpatterns variable in urls.py file:

    url(r'^static/(?P.*)$', 'django.views.static.serve', { 'document_root': settings.STATIC_ROOT} ) ,

  4. Finally, run collectstatic command in your local machine. This will copy all static files from the apps you are using:

    python manage.py collectstatic

That's it. Push in AF :)

Downside: Need to run collectstatic every time we have a new static file...

Shafiul
  • 2,832
  • 9
  • 37
  • 55
  • 1
    Hi @giga, the original question is about how to serve static content from AppFog frontend (apache httpd or nginx), not from Python app. Actually, I've already serving static files from my Python app using CherryPy (I said that in my original post), but Python program (or Java or whatever) are not as efficient serving static files as mature web servers. – Roberto Dec 31 '12 at 08:56
  • Oops. I was having trouble with serving statics by python in the first place... :P – Shafiul Jan 02 '13 at 18:10
  • So in AppFog couldn't you modify ngix.conf? – Coder Dec 01 '13 at 18:19
0

Edit your nginx.conf file. In the server section enter...

   # serve static files
      location ~ ^/(images|javascript|css)/  {
      root    /var/www/html/appname;
    }

images, javascript and css would be folders in your document root folder. Update all your urls accordingly.

Andrew Kloos
  • 4,189
  • 4
  • 28
  • 36
  • 1
    Thanks Andrew, but as far as I know AppFog doesn't allow access to http.conf apache file :-( – Roberto Nov 03 '12 at 16:15
  • Updated answer for nginx server. – Andrew Kloos Nov 03 '12 at 19:10
  • Hi Andrew as I mentioned previously I have no access to server config file, my app runs in AppFog and I only can change files inside my app dir. I've opened a ticket in Appfog to be sure if this feature is possible or not (In other PaaS system as OpenShift is possible to do it). Anyway, thanks for your answer. – Roberto Nov 06 '12 at 10:37
  • @rsc1975 Is your AppFog ticket public? If so, can you provide a link to it? I am new to AppFog but in a similar situation where I need to be able to edit the "nginx.conf" that applies to my Node.js application. – James M. Greene Nov 11 '12 at 20:35
  • @rsc1975 could you manage to fix it? I'm having exact same issues... please help. – Shafiul Dec 28 '12 at 12:34
  • Hi @giga, "my solution" was to use www.cloudflare.com as CDN to cache static content, It isn't exactly the same, but It works fine (notice that you need to purge cache in CloudFlare if you update some static content in your app). Anyway, I opened a Feature request at AppFog: https://support.appfog.com/entries/22833536-serving-static-content-through-web-server-frontend If you also need this feature you could vote for it – Roberto Dec 29 '12 at 10:01
  • Hi @james-m-green, the ticker ID is: support.appfog.com/requests/6865 (But I'm not sure if It has public access, anyway you need a free AppFog support account to access to web site) It seems that this feature is not in current AppFog roadmap. I opened a feature request in AppFog support web site as I said in my previous comment, you can vote for it if you are interested in such feature. – Roberto Dec 29 '12 at 10:07