0

I am using Webfaction for hosting one of my Django web applications. I have been using a symbolic link app to serve my media from. Recently I have been trying to set up an .htaccess file to set expiry headers on all of my images, but the .htaccess file hasn't worked. I contacted Webfaction support, and they responded with this:

"You are not seeing the expires tags in your files because you are not serving files like feature_homemobile_fieldagent.jpg from your apache stack. Everything under the /home/doc4design/webapps/django_2016/doc4_2016/media/ directory is being served by our frontend nginx server after your symlink app at https://my.webfaction.com/applications/971721/edit-application. Since our nginx server is not aware of your settings, such tags are not set. If you want to do that, you will need to remove the symlink apps and update your httpd.conf with the proper alias and location stanzas. Or build and configure your own nginx server where you will have full control over its configuration."

I tried to add a new Alias to my Apache2 configuration file, but I am getting this error

Invalid command 'Allow', perhaps misspelled or defined by a module not included in the server configuration

UPDATE

I found out being on Apache2.4 means that it is no longer 'Allow from all', and is now 'Require all granted'. I reset my server, and everything went smoothly, and I removed my Symlink app from my website temporarily through Webfaction. All the images stopped getting served, and stopped showing up on my site. I waited 10 minutes but nothing changed. Is there some extra step I'm missing ?

Apache2 httpd.conf

ServerRoot "/home/doc4design/webapps/django_2016/apache2"

LoadModule authz_core_module modules/mod_authz_core.so
LoadModule dir_module        modules/mod_dir.so
LoadModule env_module        modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module       modules/mod_mime.so
LoadModule rewrite_module    modules/mod_rewrite.so
LoadModule setenvif_module   modules/mod_setenvif.so
LoadModule wsgi_module       modules/mod_wsgi.so
LoadModule unixd_module      modules/mod_unixd.so
LoadModule headers_module    modules/mod_headers.so
LoadModule expires_module    modules/mod_expires.so
LoadModule filter_module     modules/mod_filter.so
LoadModule deflate_module    modules/mod_deflate.so
#LoadModule pagespeed_module  modules/mod_pagespeed_ap24.so

<Directory /home/doc4design/webapps/django_2016/doc4_2016>
   AllowOverride All
</Directory>

Alias /media/ /home/doc4design/webapps/django_2016/doc4_2016/media

<Directory /home/doc4design/webapps/django_2016/doc4_2016/media>
Allow from all
</Directory>

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /home/doc4design/logs/user/access_django_2016.log combined
ErrorLog /home/doc4design/logs/user/error_django_2016.log

Listen 30651
KeepAlive Off
SetEnvIf X-Forwarded-SSL on HTTPS=1
ServerLimit 1
StartServers 1
MaxRequestWorkers 5
MinSpareThreads 1
MaxSpareThreads 3
ThreadsPerChild 5

WSGIDaemonProcess django_2016 processes=2 threads=12 maximum-requests=100 python-path=/home/doc4design/webapps/django_2016:/home/doc4design/webapps/django_2016/doc4_2016:/home/doc4design/webapps/django_2$
WSGIProcessGroup django_2016
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIScriptAlias / /home/doc4design/webapps/django_2016/doc4_2016/webapp/wsgi.py
TJB
  • 3,706
  • 9
  • 51
  • 102

1 Answers1

1

I see you are still fighting.

Note: For HTTP caching headers you can specify expires max, when you create a Webfaction Static app [oficial Webfaction docs]. But expires max is tricky as it will set an expiry date long in the future, you will not be able to tell the client browser that the file was changed. You would have to rename the file (imageV1.jpg)...

enter image description here

Webfaction support should be able to set it for you if you already created the static app (not a symlink app).

You should be able to serve static using your own apache instance. You correctly mentioned that for Apache 2.4 you need to set Require all granted, however in your httpd.conf I can see you are still using Allow from all.

A simplified representation of the sections need for serving a Django App using Apache 2.4 is:

Alias /media/ /path/to/mysite.com/media/
Alias /static/ /path/to/mysite.com/static/

<Directory /path/to/mysite.com/static>
Require all granted
</Directory>

<Directory /path/to/mysite.com/media>
Require all granted
</Directory>

WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py

<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

You can also check Django Apache Serving Files, from the oficial Django Docs.

One issue particular webfaction issue I have encountered serving static assets was with permissions.

Go to www.yoursite.com/media/file.jpg
What HTTP Error Code do you get when you try to access an image?
If you get 403, try this:

chmod 710 $HOME/webapps/django_2016/doc4_2016/media/file.jpg
setfacl -m u:apache:r-x $HOME/webapps/django_2016/doc4_2016/media/file.jpg

Good luck!

ionescu77
  • 1,150
  • 10
  • 14
  • Ha yes still fighting. The number of questions I have asked has gone up by a large percentage, and there all Apache, or Apache module based. The plus side of it though is I'm learning a lot. I will give this a try. Thanks ionescu77 – TJB Sep 21 '17 at 14:37
  • Also, do I need to create a 'Static only' app in Webfaction to be able to serve files through my Apache server, or will I need no app at all ? – TJB Sep 21 '17 at 14:38
  • If you create a static only, you do not need apache for static and media. My Webfaction django setup (for one project/webiste): - I create a django app in WF panel (this will actually install an apache instance with mod_wsgi and preconfigured django project in $HOME/webapps/yourApp) - this by default will serve you Django dynamic pages - I create a static app for media (I used to put images here, but django is using MEDIA only for files uploaded through your website/project) - I create a static app for static (jpg, css, js everything django stores in STATIC) Hope this helps! Good luck – ionescu77 Sep 21 '17 at 15:23