Basic SSI not working - ssi

This is doing my nut in.
I'm trying to get server side includes to work. The server I'm hosting my site on has SSI enabled and the company that owns the servers said my issue is to do with my code, not to do with their servers.
Here's my file called test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<!--#include file="assets/includes/top.html" -->
</body>
</html>
The file top.html is just a bunch of html, nothing wrong there.
When I call the main file test.shtml it works fine. When I call it test.html it doesn't.
When I googled this, it said it's to do with file parsing. How is this anything to do with the code? What can I do to make it work with the .html file extension. (I can't use .shtml for SEO reasons).

Add the following commands to the .htaccess file:
# Enable server side includes
Options +Includes
# pass .html files to the server for parsing
AddHandler server-parsed .html
References
CGI Programming on the World Wide Web
Server Side Includes | Cheat Sheets

I had the same issue. Now I use xampp and I've added these lines before VirtualHost declarations
<Directory />
Options FollowSymLinks Indexes Includes
AllowOverride All
Order allow,deny
Allow from All
Satisfy any
AddType text/html .shtml .html .htm
AddOutputFilter INCLUDES .shtml .html .htm
<Limit PUT>
Order allow,deny
Deny from all
</Limit>
</Directory>
Hope this help

Related

Serving static files django 1.9 production Error

I have tried following the solutions in the other stack overflow posts about serving Django static files in production, but I couldn't get them to work. My static files are located inside my django app folder (league).
My CSS files are not being properly loaded; I got the following error in the console in chrome:
Resource interpreted as Stylesheet but transferred with MIME type text/html
Uncaught SyntaxError: Unexpected token !
profile:5 Uncaught SyntaxError: Unexpected token !
I think that the css files are being interpreted as html files? I don't think the javascript files are being loaded properly either...
When I checked the source file on chrome and clicked on the link to the css file, they don't work. So I am guessing that the link to the css files don't work?
The links and scripts to load the css and javascript files are:
<head>
<!-- Latest compiled and minified CSS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet" href="{% static 'league/css/bootstrap-theme.css' %}">
<link rel="stylesheet" href="{% static 'league/css/bootstrap-theme.min.css' %}">
<link rel="stylesheet" href="{% static 'league/css/bootstrap.css' %}">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script type="text/javascript" src="{% static 'league/js/bootstrap.min.js' %}"></script>
<script type="text/javascript" src="{% static 'league/js/npm.js' %}"></script>
<!-- jQuery library -->
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet" href="{% static 'league/css/f-style.css' %}">
</head>
My the relevant files in my settings.py file are as follows:
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
STATIC_URL = '/league/static/'
SITE_ID = 1
STATIC_ROOT = BASE_DIR + '/league/static/'
The configuration file on my apache server is as follows:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Alias /static /home/ubunu/project/league/static
<Directory /home/ubuntu/project/league/static>
Require all granted
</Directory>
<Directory /home/ubuntu/project/fantasy>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess project python-path=/home/ubuntu/project:/home/ubuntu/project/myprojectenv/lib/python2.7/$
WSGIProcessGroup project
WSGIScriptAlias / /home/ubuntu/project/fantasy/wsgi.py
</VirtualHost>
Thanks!
Okay this is a pretty much trivial question. There two things you need to do.
Firstly, when you are using the local python django development server, then your static files are served simply by looking up the staticfiles in the app folder, and if you specified another folder for your static files in STATIC_DIRS, then it will look into that also.
But if you are serving your file on some other server, like Nginx or Herkou or Apache in your case, then you need to collect all your static files in another directory from where your Apache will read the static files from.
To achieve the above you need to do python manage.py collectstatic
As soon as you do this, all your static files will be collected in the folder specified by the STATIC_ROOT value in your settings.py
Now secondly, if your STATIC_ROOT as well as your STATIC_URL = '/league/static/' then technically, things won't work, as those two are for different purposes.
I suggest, create a new folder at the BASE directory level, say static_root_content and change your STATIC_ROOT = os.path.join(BASE_DIR, 'static_root_content')
Now when you'll run the python manage.py collectstatic all your static data will be collected in this folder from where Apache will look up static files.
Also STATIC_DIRS and STATIC_ROOT can't have the same value in your settings.py
See this article for a better explanation -> Differences between STATICFILES_DIR, STATIC_ROOT and MEDIA_ROOT

Apache error 404 and FilesMatch

our server configuration is following:
ErrorDocument 404 http://www.domain.com/somepage
<FilesMatch "\.(gif|jpe?g|png|s?html|css|js)$">
ErrorDocument 404 default
</FilesMatch>
All "not found" pages are redirected to /somepage. If there is "not found" request for image or css or js we redirect request to standard 404 page. This works fine if image is missing in directory that exists eg
If requested file is http://www.domain.com/images/aaa/test.jgp
and exists /document_root/images/aaa/ then there is no problem and everything works as expected. Problem appears when aaa/ dir not exist .. then FilesMatch "\.(gif|jpe?g|png|s?html|css|js)$" doesnt work (is not matched) and request is send to http://www.domain.com/somepage .
Is there any way how to match not existing files (gif, jpg, css ..) in not existing directories?
Thanks
I got around this by adding the following
<LocationMatch ".+\.(jpg|png|gif)$">
ErrorDocument 404 /images/404Image.png
</LocationMatch>
Adding your extensions to the location match regex should work for you as well.

Django Admin not working / ugly - serving with nginx and gunicorn

I have nginx, gunicorn, django running on Ubuntu EC2 instance. The entire site operates fine. Except for the admin. The admin isn't displaying properly. I ran "python manage.py collectstatic" and edited the STATIC_ROOT and STATIC_URL. When I load the admin page, it's ugly, but when I inspect the source, the CSS files are located they should be
<title>Site administration | Django site admin</title>
<link rel="stylesheet" type="text/css" href="http://staticfiles.mydomain.com/static/admin/css/base.css" />
<link rel="stylesheet" type="text/css" href="http://staticfiles.mydomain.com/static/admin/css/dashboard.css" />
I can look at the nginx access.log and see the files are getting requested and delivered, but the page does not display properly. It's like the files are being received but not processed. Error log is clean.
SOLVED
Under the console tab in Chrome Developer Tools I noticed the following:
Resource interpreted as Script but transferred with MIME type text/plain: "http://staticfiles.<mydomain>.com/static/admin/js/jquery.min.js".
So the files were getting delivered to browser, but it didn't know what to do with them. To fix it I had to edit the nginx.conf and specify the default type for a couple directories ...
location /static/admin/js/ {
default_type text/javascript;
alias /home/ubuntu/webapps/<myproject>/static/admin/js/;
}
location /static/admin/css/ {
default_type text/css;
alias /home/ubuntu/webapps/<myproject>/static/admin/css/;
}
That fixed it; the django admin loads the stylesheets and javascript files and looks and operates normally. I hope this helps someone else.
My Solve ;
1.step
settings.py edit
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
STATIC_ROOT = "/opt/venv/myDjangoProject/static/"
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.FileSystemFinder',
)
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
'django.core.context_processors.request',
)
2.step
run collesctstatic in terminal :)
python manage.py collectstatic
The proper way to solve this is to add include /etc/nginx/mime.types; in the http section of the nginx configuration file.

URL not found apache

can somebody assist/point me in the right direction:
have deployed my app on a VPS and can move to various pages of my app , e.g. myIP/django-bookmarks/login or myIP/django-bookmarks/register.....however, when i click on the tabs in the app itself (e.g. register tab), it takes me to myIP/register (without the 'django-bookmarks') and then says "URL not found on this server".
how can i resolve this? note: im new when it comes to deploying and have gotten to this point after a number of errors, tutorial readings and few frustrations this past week.
my Vhost:
VirtualHost *:80>
ServerAdmin admin#example.com
ServerName django-bookmarks
DocumentRoot /var/www/django-bookmarks
# mod_wsgi settings
# WSGIDaemonProcess django-bookmarks python-path= /var/www/MyProject/django-$
WSGIProcessGroup django-bookmarks
WSGIScriptAlias /django-bookmarks /var/www/django-bookmarks/wsgi.py
# Static file alias so static files can be referenced by /static/
Alias /site_media/ /var/www/django-bookmarks/site_media
Alias /robots.txt /var/www/django-bookmarks/robots.txt
Alias /favicon.ico /var/www/django-bookmarks/favicon.ico
AliasMatch ^/([^/]*\.css) /var/www/django-bookmarks/django_bookmarks/site_m$ # Static files permissions
# Used for serving static files.
<Directory /var/www/django-bookmarks/site_media>
Order deny,allow
Allow from all
</Directory>
# Project wsgi permissions
# Used for serving django pages.
<Directory /var/www/django-bookmarks/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files> </Directory>
# Project wsgi permissions
# Used for serving django pages.
<Directory /var/www/django-bookmarks/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
wsgi.py
import os,sys
#comments
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_bookmarks.settings")
sys.path.append('/var/www/django-bookmarks')
sys.path.append('/var/www/django-bookmarks/django_bookmarks')
#comments
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
im pretty sure i made a mistake somewhere, im having a difficult time figuring out where.
any help would be appreciated.
thanks
EDIT:
base.html temp
{% block external %}{% endblock %}
</head>
<body id="home">
<div id="wrapper">
<header>
<img src="/site_media/commune.png" height="200" width="400" /><div styl$
<div class="container">
<nav>
home
popular
{% if user.is_authenticated %}
submit
search
tags
{{ user.username }}logout
{% else %}
login
register
reports
FAQ's
{% endif %}

CSS files are not appearing in production server

My css files are not working in Production server. Ive deployed using WSGI. Will you please fix my problem? Thank you
css link
<link href="{{ MEDIA_URL}}css/style.css" rel="stylesheet" type="text/css" />
settings.py
CURRENT_PATH = '/home/nibbler/code/project/
MEDIA_ROOT = os.path.join(CURRENT_PATH, 'templates/media')
MEDIA_URL = '/media/'
TEMPLATE_DIRS = (
os.path.join(CURRENT_PATH, 'templates/temp_name'),
)
site-available\default
<VirtualHost *:80>
ServerAdmin me#me.com
ServerName project.org
DocumentRoot "/home/nibbler/code/project/"
ServerName localhost
ErrorLog "/home/nibbler/code/project/logs/apache-error.log"
CustomLog "/home/nibbler/code/project/logs/apache-access.log" common
Options ExecCGI FollowSymLinks MultiViews
AddHandler wsgi-script .wsgi
WSGIDaemonProcess nibbler
WSGIProcessGroup nibbler
Alias /media /home/nibbler/code/project/templates/media/
WSGIScriptAlias / /home/nibbler/code/project/apache/django.wsgi
DirectoryIndex index.html index.cgi
AddHandler cgi-script .cgi .pl
</VirtualHost>
urls.py
if settings.DEBUG:
# static files (images, css, javascript, etc.)
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT}))
You have:
Alias /media /home/nibbler/code/project/templates/media/
wrong for a start. Try:
Alias /media/ /home/nibbler/code/project/templates/media/
They must either both have trailing slash or neither have it. You can't have one have it and the other one not have it.
BTW, having:
DocumentRoot "/home/nibbler/code/project/"
is a bad idea. Don't set DocumentRoot to be where your code is. If you were to remove WSGISriptAlias for some reason, all your code would be downloadable by external people.
You are also missing a Directory block with Allow directive in it for where WSGI script files and static files are present. This implies you have outside of this virtual host changed Apache config in some way to say that Apache can serve up files from any directory on your box, which is a bad idea as it strips away one level of security.
You have problems only with CSS files or all the media files?
MEDIA_ROOT - should be full path to your files on the system and it seems you have it, so fine.
MEDIA_URL - try to put the full URL to the media files. Try to reach them manually with the full url and see if the webserver serves them correctly. If yes, then put the full url to the MEDIA_URL.
Last thing you showed with the if settings.DEBUG is not needed in production. You really want to set DEBUG = False on production server.
By the way Django suggest to have two virtual hosts - one for the Django application itself, another one for the media (where you serve just static content directly with the http server, no dynamic stuff there).
Hope that helped a little...