Can't access Django Webpage on Ubuntu 14.04 AWS Server? - python

After launching an Ubuntu 14.04 AWS instance updating and upgrading the server, getting pip3, and successfully installing Apache2.
Changing the /etc/apache2/sites-enabled/000-default.conf file to look like:
<VirtualHost *:80>
<Directory /var/www/test>
Options +ExecCGI
DirectoryIndex index.py
</Directory>
AddHandler cgi-script .py
...
DocumentRoot /var/www/test
...
Installing mod_wsgi using:
sudo apt-get install libapache2-mod-wsgi-py3
Changing the Apache2.conf file to look like:
WSGIScriptAlias / /var/www/html/myproject/myproject/myproject/wsgi.py
WSGIPythonPath /var/www/html/myproject/myproject
<Directory /var/www/html/myproject/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
and making migrations, and running the server by typing:
python3 manage.py runserver 0.0.0.0:8000
I tried to view it at the publicdns:8000 but it said the site was unavailable. Any suggestions on getting this up and running would be greatly appreciated.
Thanks.
EDIT: As requested here is the settings.py file:
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
Here is a curl of the webserver:
curl -i http://ipaddress
HTTP/1.0 503 Service Unavailable
Cache-Control: no-cache
Connection: close
Content-Type: text/html
<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>
Curl -i with port didn't return anything at all.

Related

Django - Apache2 can't load media files from media folder

I installed an linux server with apache where I want to run my Django app. So I set everything up and when I started the app everything was shown to me except for the pictures.
I couldn't find a error inside my site.conf
<VirtualHost *:80>
ServerName MYHOST
ErrorLog ${APACHE_LOG_DIR}/mysite-error.log
CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined
WSGIDaemonProcess mysite processes=2 threads=25 python-path=/var/www/mysite
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
Alias /robots.txt /var/www/mysite/static/robots.txt
Alias /favicon.ico /var/www/mysite/static/favicon.ico
Alias /static/ /var/www/mysite/static/
Alias /static/ /var/www/mysite/media/
<Directory /var/www/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /var/www/mysite/static>
Require all granted
</Directory>
<Directory /var/www/mysite/media>
Require all granted
</Directory>
</VirtualHost>
or inside my settings.py
STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/mysite/static'
MEDIA_ROOT = '/var/www/mysite/media'
MEDIA_URL = '/media/'
What I did was setting debug = True and inside linux console I run python3 manage.py collectstatic after reloading apache the website was shown with all its css and js but for every image request I get an error 404.
Inside my templates/base.html I call {% load static %}. I tried to replace it with {% load staticfiles from static %} but that crashed my entire app (err 500)
I use Django version 3.x and apache2

Permission denied when uploading file (Django, Apache2)

I deployed a beta version of my django app to DigitalOcean and I am serving it using Apache2 for both python and static files.
Here is the issue, when I upload a file, it gives me the following error:
PermissionError at /admin/dashboard/marque/add/
[Errno 13] Permission denied: '/verauto/site/public/media/marques'
Here is an excerpt of my settings.py file, as well as the sites-available configuration for apache2:
settings.py:
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
#MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_ROOT = '/verauto/site/public/media'
MEDIA_URL = '/media/'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
#STATICFILES_DIRS = (
# os.path.join(BASE_DIR, 'verautonoapi/static'),
# os.path.join(BASE_DIR, 'boot'),
#)
#STATIC_ROOT = os.path.join(BASE_DIR, 'root')
STATIC_ROOT = '/verauto/site/public/static'
apache2 configuration:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog /verauto/site/logs/error.log
CustomLog /verauto/site/logs/access.log combined
alias /static /verauto/site/public/static
<Directory /verauto/site/public/static>
Require all granted
</Directory>
alias /media /verauto/site/public/media
<Directory /verauto/site/public/media>
Require all granted
</Directory>
<Directory /verauto/app/verauto-staging/verautonoapi/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess verauto python-path=/verauto/app/verauto-staging/ python-home=/verauto/verenv
WSGIProcessGroup verauto
WSGIScriptAlias / /verauto/app/verauto-staging/verautonoapi/wsgi.py
</VirtualHost>
As you can see, in my attempts to solve the issue, I added the media directory in the apache2 configuration, I also did the following commands for chmod rights:
sudo groupadd XXXXXX
sudo adduser www-data XXXXXX
sudo chgrp -R XXXXXX /verauto/site/public/media/
sudo chmod -R 760 /verauto/site/public/media/

Django - deployed, 403 for static but it should have permission, wsgi + Apache

my deployed Django project can't access the static files, I get 403 for all of them when inspecting in Chrome.
I added the following to my 000-default.conf where I also have the WSGIScriptAlias etc.:
Alias /static/ /home/budget/static/deploy/
<Directory /home/budget/static/deploy>
Required all granted
</Directory/
The static files exist in the budget/static/deploy folder. Should this not give the required permissions? What do I have to change to get rid of the 403?
It is running on Ubuntu 16.04.
Edit:
settings.py:
STATIC_URL = '/static/'
STATICFILES_DIRS = (
#os.path.join(BASE_DIR, 'budget/static'),
os.path.join(BASE_DIR, "static"),
)
STATIC_ROOT = os.path.join(BASE_DIR, "static/deploy/")
There may be a couple of different things that cause your configuration not to work. First of all, I would make sure that you are indeed modifying the proper Apache configuration file. You can run this command to check this:
/usr/sbin/apachectl -V | grep SERVER_CONFIG_FILE | awk '{split($0,a,"="); print a[2]}' | sed s/\"//g
Then, to delegate other API requests to django through WSGI, you should also give the correct permissions to your wsgi file (maybe this is not absolutely required for mere static serving to work):
<Directory /path/to/django/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Next, set the process information to be used by Apache as well as your binding url for your project.
WSGIDaemonProcess myproject python-path=/path/to/django/project python-home=/path/to/your/venv
WSGIProcessGroup mydjangoproject
WSGIScriptAlias /binding/url /path/to/django/project/project/wsgi.py
Lastly, you may need to set up some permissions to allow www-data to read your media and static files and you should be all set. Don't forget to restart Apache to apply the modifications.

404 Error while serving Django 1.7 static files on Apache

I've been a django developer for years now, yet a small practice project with 1.7 is giving me a great headache when it comes to serving static files.
I've set STATIC_ROOT
STATIC_ROOT = '/var/www/mydomain/static'
I've set STATIC_URL
STATIC_URL = '/static/' #as default
I'm not using STATICFILES_DIRS since I have one app called 'pages' and it's in INSTALLED_APPS. On localhost the static files are served correctly
I'm using Ubuntu 14.4 and Apache/2.4.7
My apache conf is
<VirtualHost *:80>
ServerName mydomain.net #I own the domain and pointed it correctly in GoDaddy
ServerAlias www.mydomain.net
Alias /static/ /var/www/mydomain/static
<Directory /var/www/mydomain/static>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/mydomain/mydomain/wsgi.py
<Directory /var/www/mydomain/mydomain>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess mydomain.net python-path=/var/www/mydomain:/var/www/mydomain/venv/lib/python2.7/site-packages
WSGIProcessGroup mydomain.net
</VirtualHost>
I've run collectstatic and confirmed all static files are in /var/www/mydomain/static/*.
The site loads, but I get a 404 on all css and js files.
All debugging efforts have failed. I've removed the STATIC_ROOT dir to expect a 403, but still getting a 404. I've chown'd all files/folder to root for testing; nothing. I created a deploy user and chown'd all files/folders to it; nothing. I've chown'd all files/folders to www-data; nothing!!
Is there a new config in Apache 2.4+ that's throwing me off?
What you can do is check your /var/www/mydomain path and look for the folder. I think its not there yet. If not then copy your folder to this place so that apache can serve it.
That will be worth looking

django filebrowser upload failed

I have installed a django application with django-tinymce and django-filebrowser. In my machine every thing works fine. when I deployed the application to the production, filebrowser fails to upload file and it shows me the error message Failed
Here is my settings
MEDIA_ROOT = '/srv/www/staticFiles/APCC/'
MEDIA_URL = '/static/APCC/'
STATIC_ROOT = '/srv/www/staticFiles'
STATIC_URL = '/static/'
and here is my apache configs
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE APCC.settings
PythonDebug Off
PythonOption django.root /srv/APCC
PythonPath "['/srv/APCC/'] + sys.path"
</Location>
Alias "/static/" "/srv/www/staticFiles/"
<Location "/static">
SetHandler None
Order deny,allow
Allow from all
</Location>
</VirtualHost>
I have make sure that the MEDIA_ROOT directory is created and the uploads folder required by the filebrowser is also created under it.
Also the MEDIA_ROOT directory and the uploads directories have write permissions.
I believe the problem is in my apache configuration or file structure. where would be the problem? also is there any logs specific for tinycme or filebrowser to check?

Categories

Resources