My site is working on http
I now want it to work using a SSl certificate. I've generated the keys and set up the virtualhost:
<VirtualHost *:80>
WSGIDaemonProcess pms python-path=/home/ubuntu/myapp/myapp:/home/ubuntu/myapp/env/lib/python3.4$
WSGIProcessGroup myapp
WSGIScriptAlias / /home/ubuntu/myapp/myapp/myapp/wsgi.py
<Directory /home/ubuntu/myapp/myapp/myapp>
<Files wsgi.py>
Require all granted
</Files>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ServerAdmin support#myapp.com
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/ca.crt
SSLCertificateKeyFile /etc/apache2/ssl/ca.key
ServerName leanhotelsystem.com
ServerAlias *.leanhotelsystem.com
DocumentRoot /home/ubuntu/myapp/myapp/myapp
<Directory /home/ubuntu/myapp/myapp/myapp>
<Files wsgi.py>
Require all granted
</Files>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin support#myapp.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I've also set in wsgi.py:
os.environ['HTTPS'] = "on"
and in settings.py:
WSGI_APPLICATION = 'myapp.wsgi.application'
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
The problem is that when i access the url with https it shows my folder structure, instead of rendering the homepage.
If I access via http it works fine.
Thanks!
Looks like you forget your WSGI settings section in your new VirtualHost.
Related
I want to deploy my django app on a Apache 2.4 server. The same server will host static files. The thing is that this server hosts other php based web sites.
In order for all this to work I just need to install mod_wsgi and configure apache's .conf file related to this web site, is that right?
After reading few articles I came up with this config, assuming that the web site will be in the var/www/ folder :
<VirtualHost *:80>
ServerName example.com
# Alias /events /var/www/events/html
ServerAdmin webmaster#localhost
DocumentRoot /var/www/example
Alias /media/ /var/www/example/media/
Alias /static/ /var/www/example/static/
<Directory /var/www/example/static>
Order deny,allow
Require all granted
</Directory>
<Directory /path/to/example/media>
Order deny,allow
Require all granted
</Directory>
WSGIScriptAlias / /var/www/example/events_promgruz/wsgi.py
WSGIDaemonProcess example.com python-path=/var/www/example:/opt/envs/lib/python3.6/site-packages
WSGIProcessGroup example.com
<Directory /path/to/example/example>
<Files wsgi.py>
Order allow,deny
Require all granted
</Files>
</Directory>
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What would you suggested to change or add to config?
Is there some other steps to ensure that django app will work and that it doesn't interfere other non wsgi apps?
This is what I ended up using:
<VirtualHost *:80>
ServerName expample-domen.com
ServerAdmin webmaster#localhost
Alias /static /var/www/example/static
Alias /media /var/www/example/media
<Directory /var/www/example/static>
Require all granted
</Directory>
<Directory /var/www/example/media>
Order deny,allow
Require all granted
</Directory>
<Directory /var/www/example/example>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess example python-home=/path/to/virtualEnv python-path=/var/www/example
WSGIProcessGroup example
WSGIScriptAlias / /var/www/example/example/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Hi I want to set up my django project to be access through apache2 by I.P/application_name/
So "192.0.0.0/app/" (Ip being an example)
Here is my 000-default.conf file in etc/apache2/sites-available
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIDaemonProcess HTSv2 python-home=/home/django/config/env python-path=/usr/local/django/app
WSGIProcessGroup HTSv2
WSGIScriptAlias / /usr/local/django/app/application/wsgi.py
<Directory /usr/local/django/app/application>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /usr/local/django/app/static/
<Directory /usr/local/django/app/static>
Require all granted
</Directory>
<Directory /usr/local/django/app>
Deny from all
Allow from ...
</Directory>
</VirtualHost>
When I change the line:
WSGIScriptAlias / /usr/local/django/app/application/wsgi.py
to
WSGIScriptAlias /app/ /usr/local/django/app/application/wsgi.py
I can access the home page of my application by 192.0.0.0/app/
However when I click on any buttons, obviously does not keep to this, so for example going to page1, does not go to 192.0.0.0/app/page1, it goes to 192.0.0.0/page1
How can I configure apache2 to do this? The reason I want to do this is so I can host multiple projects on the same server, so the root of 1 project is 192.0.0.0/app1/ and then the root of the other is 192.0.0.0/app2/ etc...
I am trying to run two different django projects one the same server, with two different domains. Django version is 1.8, and the webserver is Apache 2.4.7.
These are my conf files in sites-available:
#example.conf
<VirtualHost *:80>
ServerName example.com
ServerAlias example.com
ServerAdmin admin#example.com
WSGIDaemonProcess example.com python-path=/path/example/WebPortal:/path/example/venv/lib/python3.4/site-packages
WSGIProcessGroup example.com
WSGIPassAuthorization On
WSGIScriptAlias / /path/example/WebPortal/WebPortal/wsgi.py
WSGIApplicationGroup %{GLOBAL}
<Directory /path/example/WebPortal/WebPortal>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /robots.txt /path/example/WebPortal/static/robots.txt
Alias /favicon.ico /path/example/WebPortal/static/favicon.ico
Alias /media/ /path/example/WebPortal/media/
Alias /static/ /path/example/WebPortal/static/
<Directory /path/example/WebPortal/static>
Require all granted
Options -Indexes
</Directory>
<Directory /path/example/WebPortal/media>
Require all granted
Options -Indexes
</Directory>
ErrorLog "/path/example/WebPortal/logs/webportal-error.log"
CustomLog "/path/example/WebPortal/logs/webportal-access.log" combined
CustomLog "/path/example/WebPortal/logs/webportal-bandwidth.log" common
and:
#sub.example2.conf
<VirtualHost *:80>
ServerName sub.example2.com
ServerAlias sub.example2.com
ServerAdmin admin#example2.com
WSGIDaemonProcess sub.example2.com python-path=/path/sub_example2/WebPortal:/path/sub_example2/venv/lib/python3.4/site-packages
WSGIProcessGroup sub.example2.com
WSGIPassAuthorization On
WSGIScriptAlias / /path/sub_example2/WebPortal/WebPortal/wsgi.py
WSGIApplicationGroup %{GLOBAL}
<Directory /path/sub_example2/WebPortal/WebPortal>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /robots.txt /path/sub_example2/WebPortal/static/robots.txt
Alias /favicon.ico /path/sub_example2/WebPortal/static/favicon.ico
Alias /media/ /path/sub_example2/WebPortal/media/
Alias /static/ /path/sub_example2/WebPortal/static/
<Directory /path/sub_example2/WebPortal/static>
Require all granted
Options -Indexes
</Directory>
<Directory /path/sub_example2/WebPortal/media>
Require all granted
Options -Indexes
</Directory>
ErrorLog "/path/sub_example2/WebPortal/logs/webportal-error.log"
CustomLog "/path/sub_example2/WebPortal/logs/webportal-access.log" combined
CustomLog "/path/sub_example2/WebPortal/logs/webportal-bandwidth.log" common
With this configuration when I enable both, only one domain work properly...on the other one I get a Bad Request (400).
I have tried many options but no one work.
Any ideas?
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.
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.