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>
Related
I'm trying to set up a Flask webserver. I'm trying to use virtual environment with Python 3.10. I've been at it for hours, and probably have tried every suggested solution from SO, but they all don't seem to work for me https://flask.palletsprojects.com/en/2.0.x/deploying/mod_wsgi/#working-with-virtual-environments. It just keeps defaulting to the system Python version. Is it even compatible with Python3.10 yet? With the system Python 3.8 (Ubuntu 20) venv it works completely fine for some reason...
.wsgi file:
#!/var/www/html/myApp/env/bin/python3
activate_this = '/var/www/html/myApp/env/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
import sys
print(sys.version)
sys.path.insert(0, "/var/www/html/myApp/")
from flask_app import app as application
Apache:
<VirtualHost *:80>
WSGIDaemonProcess myApp python-home=/var/www/html/myApp/env/
WSGIScriptAlias / /var/www/html/confgen-webapp/myApp.wsgi
<Directory /var/www/html/myApp>
WSGIProcessGroup myApp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I have successfully deployed the Django project in my ubuntu VPS server. but when i try to install sudo certbot --apache -d amritshahi.com. I am getting the following error.
Enabling available site: /etc/apache2/sites-available/365-le-ssl.conf
Error while running apache2ctl configtest.
Action 'configtest' failed.
The Apache error log may have more information.
AH00526: Syntax error on line 25 of /etc/apache2/sites-enabled/365.conf:
Name duplicates previous WSGI daemon definition.
Rolling back to previous server configuration...
Error while running apache2ctl configtest.
Action 'configtest' failed.
The Apache error log may have more information.
AH00526: Syntax error on line 25 of /etc/apache2/sites-enabled/365.conf:
Name duplicates previous WSGI daemon definition.
inside 365.conf file:
<VirtualHost *:80>
ServerAdmin me#amritshahi.com
ServerName amritshahi.com
ServerAlias www.amritshahi.com
DocumentRoot /var/www/personal
Alias /static /var/www/personal/Personal_Blog/static
<Directory "/var/www/personal/Personal_Blog/static">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
Require all granted
</Directory>
Alias /media /var/www/personal/Personal_Blog/media
<Directory "/var/www/personal/Personal_Blog/media">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
Require all granted</Directory>
ErrorLog ${APACHE_LOG_DIR}/shahi_error.log
CustomLog ${APACHE_LOG_DIR}/shahi_access.log combined
WSGIDaemonProcess Personal_Blog python-home=/var/www/personal/Personal_>
WSGIProcessGroup Personal_Blog
WSGIScriptAlias / /var/www/personal/Personal_Blog/project/wsgi.py
<Directory /var/www/personal/Personal_Blog/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
Help Please??
Issue resloved using following step:
comment affected line
install certificate
agan come to orign one and change WSGIDaemonProcess name
restar apache server
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.!
so i'm about to lunch my first django website , i currently have a server that has been configured to host php websites and i've decided to test a simple empty project to get familiar with the process
so the python version in this server is bit old (2.6) so i couldn't install latest version of django , i installed 1.6 and since it's just a test that's not important (im going to upgrade python version when my website is ready to lunch )
so i've installed django and created a new project called testing in this dire
/home/sdfds34fre/public_html/
which you can see using this domain
http://novadmin20.com
and after reading documentation on django (unfortunately they have removed doc for 1.6 and i had to use 1.9) and wsgi i've updated my httpd.conf like this
<VirtualHost 111.111.111.111:80>
ServerName 111.111.111.111
DocumentRoot /usr/local/apache/htdocs
ServerAdmin somemeail#gmail.com
<IfModule mod_suphp.c>
suPHP_UserGroup nobody nobody
</IfModule>
<Directory /home/sdfds34fre/public_html/testing/testing>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess testing python-path=/home/sdfds34fre/public_html/testing:/usr/lib64/python2.6/site-packages/
WSGIProcessGroup testing
WSGIScriptAlias / /home/sdfds34fre/public_html/testing/testing/wsgi.py
</VirtualHost>
but even after restarting httpd service when i go to
http://novadmin20.com/testing/
all i see is directory list , am i missing something ?
here is my wsgi.py file
"""
WSGI config for testing project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testing.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
DocumentRoot directive is the main root of your problem. (ref)
try this config:
<VirtualHost 111.111.111.111*:80>
ServerName novadmin20.com
WSGIDaemonProcess testing python-path=/home/sdfds34fre/public_html/testing:/usr/lib64/python2.6/site-packages/
WSGIScriptAlias / /home/sdfds34fre/public_html/testing/testing/wsgi.py
<Directory /home/sdfds34fre/public_html/testing/testing>
<Files wsgi.py>
Order deny,allow
Require all granted
WSGIProcessGroup testing
</Files>
</Directory>
</VirtualHost>
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.