I have a virtual machine running peppermint os 2 (basically ubuntu).
I've been trying to follow the following tutorial: http://jeffbaier.com/articles/installing-django-on-an-ubuntu-linux-server/
and so far everything has worked out as the tutorial has stated. My Apache httpd.conf file looks like the following:
ServerName localhost
MaxRequestsPerChild 1
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myproject.settings
PythonPath "['/home/<my_user_name>/django_projects'] + sys.path"
SetHandler None
SetHandler None
SetHandler None
SetHandler None
Whenever I try and and go into "localhost/", it shows me the /var/www/ folder (the index.html file that says "It works!") and not a django startpage that should come up. The contents of my /var/www are "admin_media" and "media"
What do I need to do?
Thank you.
try mod_wsgi or uwsgi, it's easier to config, robust, and much faster.
you could also get help at django doc - use django with mod_wsgi
as you are using ubuntu, the install of mod_wsgi is easy:
sudo apt-get install libapache2-mod-wsgi
if this does not have mod-wsgi enabled, do as following:
cd /etc/apache2/mod_available
cp mod_wsgi.* ../mod_enable
sudo service apache2 restart
for using mod_python, the apache config is:
ameVirtualHost *:80
NameVirtualHost *:8000
Listen 80
Listen 8000
WSGIDaemonProcess xxxx display-name=%{GROUP}
WSGIProcessGroup xxxx
<VirtualHost *:80>
ServerName xxxx
WSGIScriptAlias / /home/xxx/xxxx/xxxx.wsgi
Alias /js "/home/xxx/xxxx/xxxx/public/js"
<Location "/js">
SetHandler None
</Location>
<Directory "/home/xxx/xxxx/xxxx/public/js">
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
NameVirtualHost *:8080
<VirtualHost *:8080>
WSGIScriptAlias / /home/xxxx/xxxx/wsgi_handler.py
#WSGIDaemonProcess xxxx_com22 user=xxxx processes=1 threads=10
#WSGIProcessGroup xxxx_com1
Alias /upload/ "/home/xxxx/xxxx/upload/"
<Directory /home/xxxx/xxxx/upload/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Listen 8080
and for using uwsgi, my recommend is using nginx + uwsgi, if you are interesting, I'll post the tutorial and configuration.
Related
I have installed Django and created a new project using the following commands:
mkdir trydjango
cd trydjango
virtualenv -p python3 .
source bin/activate
pip install django==2.0.7
When I run pip freeze, I see the following:
Django==2.0.7
pkg-resources==0.0.0
pytz==2018.9
Inside my virtualhost I have the following:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName django.mydomain.com
ServerAlias www.django.mydomain.com
DocumentRoot /var/www/django.mydomain.com
ErrorLog ${APACHE_LOG_DIR}/django.mydomain.com.error.log
CustomLog ${APACHE_LOG_DIR}/django.mydomain.com.access.log combined
<Directory root/Dev/trydjango/src/trydjango>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIApplicationGroup %{GLOBAL}
WSGIDaemonProcess trydjango python-home=root/Dev/trydjango/bin python-path=root/Dev/trydjango/
WSGIProcessGroup trydjango
WSGIScriptAlias / /root/Dev/trydjango/src/trydjango/wsgi.py
</VirtualHost>
But when I try to access my domain, it time outs.
When I access the Apache error log for the domain the following error message is present:
[pid 12746] [client xx.xx.xx.xxx:60684] Timeout when reading response
headers from daemon process 'trydjango':
/root/Dev/trydjango/src/trydjango/wsgi.py
How can I fix this timeout problem?
I've chowned wsgi.py to www-data:www-data
I've also made the folder the app is in exectuable
Not sure what else to try with this brand new project to get wsgi working.
I found this: Django Webfaction 'Timeout when reading response headers from daemon process'
and added WSGIApplicationGroup %{GLOBAL} to the virtualhost and also to apache2.conf but this didn't fix the problem.
i just fix a problem like that, but widht flask-wsgi, i think is the same " Timeout when reading response headers from daemon process ",
just go to the folder "/etc/httpd/conf.d/"(in centos), in the file of configuration of python-wsgi, in my case "python-wsgi.conf",
Listen 5002
<VirtualHost 192.168.150.62:5002>
ServerAdmin webmaster#localhost
#DocumentRoot /var/www/html
DocumentRoot /home/XXXXXXx/XXXXXXXXX
ServerAlias XXXXXXXXXXXXXX
ServerName XXXXXXXXXXXXXXX
LogLevel debug
WSGIDaemonProcess xxxxxxxxxxxxxxxxx python-path=/home/XXXXX/XXXXXXXXXX:/home/XXXXXX/XXXXXXXXX/venv/lib/python3.6/site-packages
WSGIProcessGroup XXXXXXXXXXXXXXX
WSGIScriptAlias / /home/XXXXX/XXXXXXXXXXXXX/app.wsgi
WSGIPassAuthorization On
WSGIChunkedRequest On
ErrorLog logs/error-5000-dev.log
CustomLog logs/access-5000-dev.log combined
<Directory /home/XXXXX/XXXXXXXXXXXXXXX>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/XXXXXX.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/xxxxxxxx.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/xxxxxxxxx.com/chain.pem
SetEnv nokeepalive ssl-unclean-shutdown
TimeOut 18000
look, i put a set property "TimeOut" in the final of the file, i put a big amount of second for test 18000, and works for me, of course, you must restart the service apache,"service httpd restart" after the change. by default is 60 second, if you dont touch it. try thata and tell me if you solved the problem.good luck.!
i want open django server using apache and mod_wsgi.
i wrote down as below
sudo apt-get install apache2
sudo apt-get install libapache2-mod-wsgi
and create django project and app and i add my bot in setting.py
and create virtual environment and using
and add below code in seoultech/wsgi.py /django = mydirctory/ seoultech=project/bot =app /
import os, sys
sys.path.append('/home/django')
sys.path.append('/home/django/venv/lib/python2.7/site-packages')
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "seoultech.settings")
application = get_wsgi_application()
and cd /etc/apache2/site-available/000-default.conf
add code
WSGIDaemonProcess seoultech python-path=/home/django/seoultech=home/django
/venv/lib/python2.7/site-packages
<VirtualHost *:80>
ServerAdmin webmaster#localhost
WSGIScriptAlias / /home/django/seoultech/wsgi.py
<Directory /home/django/seoultech>
<Files wsgi.py>
Require all granted
</Files>
</Directory
</VirtualHost>
but sudo apachectl-k start i got error
'AH00526: Syntax error on line 1 of /etc/apache2/sites-enabled
/000default.conf:Invalid command 'WSGIDaemonProcess', perhaps misspelled
or defined by a module not included in the server configuration Action '-k
start' failed.The Apache error log may have more information.'
im looking forward to help
Place WSGIDaemonProcess inside of VirtualHost to get rid of this error.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
WSGIDaemonProcess seoultech python-path=/home/django/seoultech=home/django
/venv/lib/python2.7/site-packages
WSGIScriptAlias / /home/django/seoultech/wsgi.py
<Directory /home/django/seoultech>
<Files wsgi.py>
Require all granted
</Files>
</Directory
</VirtualHost>
I'm trying to deplay my Flask application on a RHEL7 Apache 2.4 server.
File structure is the following inside /var/www/html
/app
app.wsgi
/app
app.py
/templates
/static
In my /etc/httpd/conf/httpd.conf I have the following code to set up my project:
<VirtualHost *>
ServerName 10.65.112.75:443
WSGIDaemonProcess app user=apache group=apache threads=5 home=/var/www/html/app/app
WSGIScriptAlias / /var/html/app/app.wsgi
<Directory /var/www/html/app/app/>
WSGIProcessGroup app
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Require all granted
</Directory>
Alias /static /var/www/html/app/app/static/
<Directory /var/www/html/app/app/static/>
Order deny,allow
Require all granted
</Directory>
And my app.wsgi contains the following:
#!/usr/bin/python
import sys
sys.path.insert(0, "/var/www/html/app/app/")
from app import app as application
The code for the project itself can be found in my github repository here.
I do not get any errors when trying to browse the server. It just doesnt do anything. Running my script from the terminal works, though.
Thanks for the help.
There are various things which aren't right.
You have:
WSGIScriptAlias / /var/html/app/app.wsgi
whereas it appears it should be:
WSGIScriptAlias / /var/www/html/app/app.wsgi
And:
<Directory /var/www/html/app/app/>
appears it should be:
<Directory /var/www/html/app>
Your VirtualHost definition also looks wrong. You have:
<VirtualHost *>
ServerName 10.65.112.75:443
If you really want this to be for HTTPS connections, you are missing all the SSL directives to add a SSL certificate.
ServerName would also usually be a fully qualified domain name and not an IP:PORT. The port number would usually be in the VirtualHost directive. For example, for HTTP, use:
<VirtualHost *:80>
ServerName my.host.name
where my.host.name is the full public host name for your machine which you use in the URL, not an IP address.
We're looking for a clean and isolated way to host several Django sites on a single Apache with vhosts on Ubuntu 14.04.
Following the docs https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode
and Where should WSGIPythonPath point in my virtualenv? , we set the following setup :
Have a global virtualenv for mod_wsgi
virtualenv -p /usr/bin/python3 /home/admin/vhosts_venv
. vhosts_venv/bin/activate
pip install mod-wsgi
sudo /home/admin/vhosts_venv/bin/mod_wsgi-express install-module
sudo vi /etc/apache2/mods-available/wsgi_express.load
added :
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py34.cpython-34m.so
Then have a vhost venv and a basic app :
virtualenv -p /usr/bin/python3 /home/admin/vhost1_venv
. vhost1_venv/bin/activate
pip install Django
pip install PyMySQL
django-admin startproject vhost1
cd vhost1
python manage.py startapp main
Setup host resolution with :
sudo vi /etc/hosts
updated :
127.0.0.1 localhost vhost1.example.com
Setup Apache vhost with :
<VirtualHost vhost1.example.com:80>
ServerName vhost1.example.com
ServerAlias example.com
ServerAdmin webmaster#localhost
#DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/vhost1_error.log
CustomLog ${APACHE_LOG_DIR}/vhost1_access.log combined
WSGIProcessGroup vhost1.example.com
WSGIScriptAlias / /home/admin/vhost1/vhost1/wsgi.py process-group=vhost1.example.com
WSGIDaemonProcess vhost1.example.com user=www-data group=www-data threads=25 python-path=/home/admin/vhost1:/home/admin/vhost1_venv/lib/python3.4/site-packages:/home/admin/vhosts_venv/lib/python3.4/site-packages
<Directory /home/admin/vhost1>
<Files wsgi.py>
<IfVersion < 2.3>
Order deny,allow
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
</Files>
</Directory>
</VirtualHost>
Enabled everything with :
sudo a2enmod wsgi_express
sudo a2ensite vhost1
sudo service apache2 restart
When testing it, we get 2 answers for a single curl request, delivered in 2 timing (sometime like 0.5s between each) :
curl vhost1.example.com
It worked! Congratulations on your first Django-powered page.
Of course, you haven't actually done any work yet. Next, start your
first app by running python manage.py startapp [app_label].
You're seeing this message because you have DEBUG = True in your
Django settings file and you haven't configured any URLs. Get to work!
Directly followed by :
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator at webmaster#localhost to
inform them of the time this error occurred, and the actions you
performed just before this error.
More information about this error may be available in the server error
log. Apache/2.4.7 (Ubuntu) Server at vhost1.example.com Port 80
In /var/log/apache2/error.log, we get :
[Mon Aug 15 15:37:42.754139 2016] [core:notice] [pid 18622:tid
140151787534208] AH00051: child pid 18717 exit signal Segmentation
fault (11) , possible coredump in /etc/apache2
and in /var/log/apache2/vhost1_access.log :
127.0.0.1 - - [15/Aug/2016:15:37:42 +0200] "GET / HTTP/1.1" 500 2593 "-" "curl/7.35.0"
How to set it up correctly?
To summarize Graham Dumpleton's answer
mod_wsgi 4.5.4 was broken with Python3. 4.5.5 fixed it.
It's possible to setup a Python virtualenv for the virtualhosting (with package mod_wsgi) but is recommended to setup a Python virtualenv using python-home option and not python-path.
It's recommended to set WSGIRestrictEmbedded On according to http://blog.dscpl.com.au/2009/11/save-on-memory-with-modwsgi-30.html
/etc/apache2/mods-available/wsgi_express.conf looks like :
WSGIRestrictEmbedded On
/etc/apache2/sites-available/vhost1.conf looks like :
<VirtualHost vhost1.example.com:80>
ServerName vhost1.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/vhost1_error.log
CustomLog ${APACHE_LOG_DIR}/vhost1_access.log combined
WSGIDaemonProcess vhost1.example.com threads=15 python-home=/home/admin/vhost1_venv python-path=/home/admin/vhost1
WSGIScriptAlias / /home/admin/vhost1/vhost1/wsgi.py process-group=vhost1.example.com application-group=%{GLOBAL}
<Directory /home/admin/vhost1>
<Files wsgi.py>
<IfVersion < 2.3>
Order deny,allow
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
</Files>
</Directory>
</VirtualHost>
I want use django on my ubuntu localhost with apache 2.4. I installed mod_wsgi using
sudo aptitude install libapache2-mod-wsgi
I want point my app written in django
My /etc/apache2/sites-available/wiersze.td.conf
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName wiersze.td
#DocumentRoot /
WSGIScriptAlias / /home/s/py/django/kitty/kitty/wsgi.py
Alias / /home/s/py/django/kitty/kitty/
Alias /adminmedia/ /opt/python2.7/lib/python2.7/site-packages/django/contrib/admin/media/
<Directory "/home/s/py/django/kitty/kitty/">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
after enable my site and added hosts I see my files inside kitty directory. Why I cant see my index view?
I think there is problem with alias. Remove following line, restart Apache and retry browsing your site:
Alias / /home/s/py/django/kitty/kitty/
Thanks