How to serve static content with Apache in AppFog (WSGI Python app)

独自空忆成欢 提交于 2019-12-05 00:06:19

问题


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.


回答1:


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...




回答2:


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.



来源:https://stackoverflow.com/questions/13208293/how-to-serve-static-content-with-apache-in-appfog-wsgi-python-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!