Getting Error Forbidden, you don't have permission to access this resource, when hosting my website with apache2 on port 443 - django

my django website hosted on AWS EC2 apache ubuntu has ssl certificate obtained and setup through certbot but it is not opening on port 443(HTTPS).It is showing error Forbidden 403.
There might be some permission issues. I have executed sudo chmod -R 775 /path/to/webroot/directory, sudo chown -R user:group /path/to/webroot/directory commands.
apache2.conf
<Directory />
Options FollowSymLinks
#Options Indexes FollowSymLinks
AllowOverride None
#Order deny,allow
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory "/var/www">
AllowOverride None
Require all granted
</Directory>
#<Directory /srv/>
#Options Indexes FollowSymLinks
#AllowOverride None
#Require all granted
#</Directory>
000-default.conf
<VirtualHost *:80>
#ServerName logyanlo.com
#ServerAlias www.logyanlo.com
ServerAdmin webmaster#localhost
DocumentRoot /home/ubuntu/blog/gyanlo
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/ubuntu/blog/gyanlo/static
<Directory /home/ubuntu/blog/gyanlo/static>
Require all granted
</Directory>
<Directory /home/ubuntu/blog/gyanlo/gyanlo>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess gyanlo python-path=/home/ubuntu/blog/gyanlo/ python-home=/home/ubuntu/blog/gyanlo_env
WSGIProcessGroup gyanlo
WSGIScriptAlias / /home/ubuntu/blog/gyanlo/gyanlo/wsgi.py
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.logyanlo.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

Related

Apache error on ubuntu ERROR: Site (SiteName) does not exist

I'm facing a problem when I run sudo a2ensite test.watermaps-eg.com.conf to add a new site to apache2 it gives me ERROR: Site test.watermaps-eg.com does not exist!
What I tried to do
Added the file test.watermaps-eg.com.conf inside sites-enabled.
Added the apache2 configurations inside the file.
<VirtualHost *:80>
ServerName https://test.watermaps-eg.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#innoventiq.com
ServerName test.watermaps-eg.com
DocumentRoot /home/ubuntu/test_water_maps_django
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/ubuntu/test_water_maps_django/static
<Directory /home/ubuntu/test_water_maps_django/static>
Require all granted
Order Allow,Deny
Allow from all
AllowOverride all
</Directory>
<Directory /home/ubuntu/test_water_maps_django/kml_files>
Require all granted
</Directory>
<Directory /home/ubuntu/test_water_maps_django/water_maps>
Require all granted
Order Allow,Deny
Allow from all
AllowOverride all
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess test_water_maps_django python-path=/home/ubuntu/test_water_maps_django python-home=/home/ubuntu/test_water_maps_django/venv
WSGIProcessGroup test_water_maps_django
WSGIScriptAlias / /home/ubuntu/test_water_maps_django/water_maps/wsgi.py
WSGIPassAuthorization On
</VirtualHost>
I ran the command sudo a2ensite test.watermaps-eg.com.conf and it returns the mentioned above error.
You might want to add the conf (test.watermaps-eg.com.conf) file inside /etc/apache2/site-available
before running the command
sudo a2ensite test.watermaps-eg.com

Unable to connect to WSGI daemon process 'sampleapp'

I tried to install django in ubuntu server and i had 503 error in error.log
my apache2.conf is:
<VirtualHost x.xxx.xxx.xxx:8080>
ServerAlias www.samplesite.com
ServerAdmin info#samplesite.com
DocumentRoot /var/www/sampleapp/
ScriptAlias /cgi-bin/ /var/www/sampleapp/cgi-bin/
Alias /vstats/ /var/www/sampleapp/stats/
Alias /error/ /var/www/sampleapp/document_error
#SuexecUserGroup admin admin
CustomLog /var/log/apache2/domains/sampleapp.ir.bytes bytes
CustomLog /var/log/apache2/domains/sampleapp.ir.log combined
ErrorLog /var/log/apache2/domains/sampleapp.ir.error.log
WSGIProcessGroup sampleapp
WSGIScriptAlias /sampleapp /var/www/sampleapp/sampleapp/wsgi.py
WSGIDaemonProcess sampleapp python-path=/var/www/sampleapp:/var/www /sampleapp/envme/lib/python3.4/site-packages
<Directory /var/www/sampleapp/static/>
Require all granted
</Directory>
<Directory /var/www/sampleapp/media/>
Require all granted
</Directory>
<Directory /var/www/sampleapp/sampleapp/>
<Files wsgi.py>
require all granted
</Files>
</Directory>
<Directory /var/www/sampleapp/>
AllowOverride All
Options +Includes +Indexes +ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and i have this error in my error.log:
(13)Permission denied: [client x.xxx.xx.xxx:59504] mod_wsgi (pid=26905): Unable to connect to WSGI daemon process 'sampleapp' on '/var/run/apache2/wsgi.26899.0.1.sock' as user with uid=1005.
I lost 2 days trying to solve it,
You can refer this url,
http://code.google.com/p/modwsgi/wiki/ConfigurationIssues#Location_Of_UNIX_Sockets
Adding this,
WSGISocketPrefix run/wsgi
will solve the error. The solution is to change where the socket files are kept to a location where Apache user can read them.

Configuring Apache with Django

I'm trying to configure Apache with Django. Everything is working except the admin panel. It's static files are not loading. The documentation talks about different ways of doing it but none are working for me.
Here is my 0000-default.conf:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin maahd#meddy.co
DocumentRoot /var/www/html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
Alias /static /var/www/html/sp-django-master/meddy1/static
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
include sites-available/meddy.co.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Here is my meddy.co.conf where meddy.co is my website:
<VirtualHost *:80>
ServerName ec2-54-254-141-40.ap-southeast-1.compute.amazonaws.com
ServerAlias www.ec2-54-254-141-40.ap-southeast-1.compute.amazonaws.com
WSGIScriptAlias / /var/www/html/sp-django-master/meddy.wsgi
DocumentRoot /var/www/html/sp-django-master
#Alias /static /var/www/html/sp-django-master/meddy1/static
<Location "/static/">
Options -Indexes
</Location>
#AliasMatch ^/([^/]*\.css) /var/www/html/sp-django-master/meddy1/static/meddy1/css/$1
AliasMatch ^/([^/meddy1]*\.css) /var/www/html/sp-django-master/meddy1/static/meddy1/css/$1
AliasMatch ^/([^/admin]*\.css) /var/www/html/sp-django-master/static/admin/css/$1
Alias /static/ /var/www/html/sp-django-master/meddy1/static/
<Directory /var/www/html/sp-django-master/meddy1/static>
Require all granted
</Directory>
<Directory /var/www/html/sp-django-master/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /media/ /var/www/html/sp-django-master/uploads/
<Directory /var/www/html/sp-django-master/uploads>
Require all granted
</Directory>
Alias /static/admin/ /var/www/html/sp-django-master/static/admin/
</VirtualHost>
Any help would be appreciated.

running two django apps with SSL in same apache server

I have apache2 installed in ubuntu lucid ,and have enabled ssl .Now I am running a django app (lets say myapp1 )on it using mod_wsgi.
I have configured the /etc/apache2/sites_enabled/ssl file and /etc/apache2/sites-available/ssl as below.
Now I can run my app using the url
https://127.0.0.1/myapp1
I need to run another django app (say myapp2 )in the same server,and that also uses SSL.So,how should I configure it?Can somebody please help me?
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /home/me/dev/python/django/myapp1
SSLEngine on
SSLOptions +StrictRequire
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
WSGIScriptAlias /myapp1 /home/me/dev/python/django/myapp1/myapp1.wsgi
Alias /site_media/ /home/me/dev/python/django/myapp1/media/
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
By adding:
WSGIScriptAlias /myapp2 /home/me/dev/python/django/myapp2/myapp2.wsgi
You will need to resolve any conflict though if they can't share the same static media files. That is, have each have media in different locations and configure settings for each Django project appropriately.

problem using WSGIApplicationGroup %{GLOBAL} in apache configuration

im using django with apache and mod_wsgi
i am facing a problem when i use WSGIApplicationGroup %{GLOBAL} in apache configuration file (.conf) . i dont know if i am using this directive correctly or i need to use it in another way , the problem is that i needed to add this directive to fix a problem for xapian as described in this ticket (http://trac.xapian.org/ticket/185) after that the search started to work but all my sites contents got mixed up, meaning site1 content appears on site2.when i removed WSGIApplicationGroup %{GLOBAL} , sites are rendering properly again but search stopped working.
here is my .conf file contents:
NameVirtualHost my_ip_address:80
WSGIApplicationGroup %{GLOBAL}
<VirtualHost my_ip_address:80>
ServerName www.site1.com
ServerAlias site1
WSGIScriptAlias / "/home/sa/www/site1/apache/django.wsgi"
<Directory "/home/sa/www/site1/apache">
Allow from all
</Directory>
Alias /site_media/ "/home/sa/www/site1/media/"
<Directory "/home/sa/www/site1/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
WSGIApplicationGroup %{GLOBAL}
<VirtualHost my_ip_address:80>
ServerName www.site2.com
ServerAlias site2
WSGIScriptAlias / "/home/sa/www/site2/apache/django.wsgi"
<Directory "/home/sa/www/site2/apache">
Allow from all
</Directory>
Alias /site_media/ "/home/sa/www/site2/media/"
<Directory "/home/sa/www/site2/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/"
<Directory "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
WSGIApplicationGroup %{GLOBAL}
< VirtualHost my_ip_address:80 >
ServerName www.site3.com
ServerAlias site3
WSGIScriptAlias / "/home/sa/www/site3/apache/django.wsgi"
<Directory "/home/sa/www/site3/apache">
Allow from all
</Directory>
Alias /site_media/ "/home/sa/www/site3/media/"
<Directory "/home/sa/www/site3/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/"
<Directory "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
WSGIApplicationGroup %{GLOBAL}
<VirtualHost my_ip_address:80>
ServerName www.site4.com
ServerAlias site4
WSGIScriptAlias / "/home/sa/www/site4/apache/django.wsgi"
<Directory "/home/sa/www/site4/apache">
Allow from all
</Directory>
Alias /site_media/ "/home/sa/www/site4/media/"
<Directory "/home/sa/www/site4/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/"
<Directory "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
WSGIApplicationGroup %{GLOBAL}
<VirtualHost my_ip_address:80>
ServerName www.site5.com
ServerAlias site5
WSGIScriptAlias / "/home/sa/www/site5/apache/django.wsgi"
<Directory "/home/sa/www/site5/apache">
Allow from all
</Directory>
Alias /site_media/ "/home/sa/www/site5/media/"
<Directory "/home/sa/www/site5/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/"
<Directory "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
has anybody faced this issue
any suggestions
thanks
Django's implementation prevents multiple Django instances running in same interpreter (application group). Thus if running multiple Django sites on same Apache server and must set WSGIApplicationGroup to %{GLOBAL}, then you MUST use daemon mode and delegate each Django site to a separate daemon process group. Daemon mode is preferred anyway.
Ensure you read:
http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
The latter explaining part why daemon mode is good as far as making code reloading easier.