So i'm trying to deploy a simple website using django, Apache, and wsgi. I wrote my conf file using the django guide (https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/) and this previous answer (Deploying Django on Apache and WSGI) but when I restart Apache I get an syntax error on line 3 stating WSGIPythonPath cannot occur within the VirtualHost section, once removed Apache restarted successfully but still does not redirect to the appropriate django website I created even after changing the hosts files so that it redirects back to my server.
Apache Version: 2.4.7
Python Version: 2.7.6
Django Version: 1.8.3
<VirtualHost *:80>
WSGIScriptAlias / /var/www/mywebsite/mywebsite/wsgi.py
WSGIPythonPath /var/www/mywebsite
ServerAdmin my_email#gmail.com
ServerName mywebsite.com
ServerAlias www.mywebsite.com
<Directory /var/www/mywebsite/mywebsite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
move the line with WSGIPythonPath to the httpd.conf location
Related
I was deploying my django app on my VPS using the apache web server.
It works totally fine on http://192.46.209.82:8000/ but when I try to access the same using my IP address, 192.46.209.82. I get
Forbidden
You don't have permission to access this resource.
Apache/2.4.41 (Ubuntu) Server at 192.46.209.82 Port 80
Here is my conf file
nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#example.com
DocumentRoot /root/django/myproject
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /root/django/myproject/static
<Directory /root/django/myproject/static>
Require all granted
</Directory>
<Directory /root/django/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-path=/root/django/myproject python-home=/root/django/myprojectenv
WSGIProcessGroup myproject
WSGIScriptAlias / /root/django/myproject/myproject/wsgi.py
</VirtualHost>
I am using python's virtual environment, where myprojectenv is my virtual env path and the pwd is /root/django
Note : I tried the answer from the question that I was getting as suggestion to this question but that did not work for me.
EDIT : Updated permission
In my case even though I set up all the permission correctly, I still was getting error so I moved my entire project and virtual environment to /opt and it worked for me for now. But I would like to know the reason why it was not working under /home even when I gave all permissions
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
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 want to get django to run on https server securely without using thirdparty packages like runsslserver, or sslserver for that i was this approach
in the settings.py file i have configured these line.
SECURE_SSL_REDIRECT = True
so when giving the url in the browser url able to redirect to https://192.168.31.2/cp_vm/details but i'm getting secure ssl error.
please suggest me any ways to get the output, or running the django on apache with https also fine but i'm able to find the links
https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04
but after that giving the ip in the browser 192.168.41.5/cp_vm/details it shows unable to connect.
i'm attaching the apache 000.default.conf file also please help me in this, Pleas forgive me if any mistakes in the above kindly suggest me some pointers so that
I can run django on apache server first .
Then getting the https// on the same apache server. please provide me some help would be great if any helping hands.
My config file as follows:
<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
ServerName 10.206.51.6
ServerAdmin 10.206.51.6
#ServerAdmin webmaster#localhost
#DocumentRoot /var/www/html
DocumentRoot /var/www/nfvs_portal
## imc urls
ProxyPass /imc http://10.206.50.12:8080/imc
ProxyPassReverse /imc http://10.206.50.12:8080/imc
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
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
# 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
Alias /static /opt/hpe_nfvs/nfvs_portal/static
<Directory /opt/hpe_nfvs/nfvs_portal/static>
Require all granted
</Directory>
<Directory /opt/hpe_nfvs/nfvs_portal/nfvs_portal>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess nfvs_portal python-path=//opt/hpe_nfvs/nfvs_portal:/opt/hpe_nfvs/nfvs_portal/nfvs_portal/lib/python2.7/site-packages
WSGIScriptAlias / /opt/hpe_nfvs/nfvs_portal/nfvs_portal/wsgi.py
</VirtualHost>
I faced a lot of troubles and did a lot of homework to complete django site + apache with https configuration on my ubuntu server. And finally, I could able to get it configured successfully and my site is working as expected with https now.
The below are the .py and apache configuration files. Please correct your files and let me know if you still face any issues.
wigs.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE","go_portal_site.settings")
os.environ['HTTPS'] = "on"
application = get_wsgi_application()
/etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
redirect permanent / https://site.site.com
Alias /static /home/ubuntu/django_portal/ci/site_portal/portal_site/static
<Directory /home/ubuntu/django_portal/ci/site_portal/portal_site/static>
Require all granted
</Directory>
<Directory /home/ubuntu/django_portal/ci/site_portal/portal_site/go_portal_site>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
#WSGIDaemonProcess go_portal_site python-path=/home/ubuntu/django_portal/ci/site_portal/portal_site python-home=/home/ubuntu/django_portal/ci/site_portal/portal_site/phase2_env
WSGIProcessGroup go_portal_site
WSGIScriptAlias / /home/ubuntu/django_portal/ci/site_portal/portal_site/go_portal_site/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerName site.site.com
Alias /static /home/ubuntu/django_portal/ci/site_portal/portal_site/static
<Directory /home/ubuntu/django_portal/ci/site_portal/portal_site/static>
Require all granted
</Directory>
<Directory /home/ubuntu/django_portal/ci/site_portal/portal_site/go_portal_site>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess go_portal_site python-path=/home/ubuntu/django_portal/ci/site_portal/portal_site python-home=/home/ubuntu/django_portal/ci/site_portal/portal_site/phase2_env
WSGIProcessGroup go_portal_site
WSGIScriptAlias / /home/ubuntu/django_portal/ci/site_portal/portal_site/go_portal_site/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/site.site.com-cer.pem
SSLCertificateKeyFile /etc/apache2/ssl/site.site.com-key.pem
</VirtualHost>
(phase2_env) ubuntu#ip-10-0-10-125:~/django_portal/ci/site_portal/portal_site$ sudo service apache2 restart
* Restarting web server apache2 [ OK ]
(phase2_env) ubuntu#ip-10-0-10-125:~/django_portal/ci/site_portal/portal_site$
On top of the HTTP server, you need to run an SSL server with Apache2, i.e. configure a <VirtualHost *:443>. Also, I would let Apache2 handle the redirection instead of Django.
<VirtualHost *:80>
# Virtual host for the redirection
ServerName 10.206.51.6
ServerAdmin 10.206.51.6 # <- This should be an email!
DocumentRoot /dev/null/
Redirect permanent / https://10.206.51.6/ # Redirects also what is after the "/"
</VirtualHost>
<VirtualHost *:443>
# SSL site
ServerName 10.206.51.6
ServerAdmin 10.206.51.6 # <- This should be an email!
DocumentRoot /var/www/nfvs_portal/
SSLCertificateFile /etc/apache2/certs/your-server-certificate.pem
SSLCertificateKeyFile /etc/apache2/certs/your-server-certificate.key.pem
# ... [The rest of your site configuration]
</VirtualHost>
If you get into trouble even with this configuration, I would split the problem in (1) making Apache2 manage to redirect and serve a static SSL page in your document root (without using WSGI), and (2) modify that configuration to use your Django site.
I am having difficulty troubleshooting this issue. I have a Django app running on an Ubuntu 14.04 server (with Apache 2.4 and mod_wsgi for Python 3.4). It connects to SQL Server via pymssql.
In development, the app works fine. I query the database, and the database returns the expected results.
In production (under the Apache user), however, the script hangs at the exact point that a database query is made. My browser (Chrome or Firefox) shows a spinning wheel that continues to spin as long as the browser window is open.
I have the following in my apache2.conf file:
ServerName localhost
# WSGIDaemonProcess application
WSGIPythonPath /home/production_code/python3env/lib/python3.4/site-packages:/home/production_code/school
# WSGIProcessGroup application
WSGIScriptAlias / /home/production_code/school/school/wsgi.py
# Python virtualenv home
WSGIPythonHome /home/production_code/python3env
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
And the following in my sites-enabled/000-default.conf file:
<VirtualHost *:80>
ServerAdmin *****#school.edu
ServerName localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static/ /home/production_code/school/static/
<Directory /home/production_code/school/>
Require all granted
</Directory>
<Directory /home/production_code/school/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/production_code/school/static>
Require all granted
</Directory>
</VirtualHost>
Does anyone have any idea what might be causing this or how I might troubleshoot this? The Apache error logs and access logs are not particularly helpful in this situation, since a response to the request is never rendered. Similarly, Django debugging is also not useful here.
Instead of:
# WSGIDaemonProcess application
WSGIPythonPath /home/production_code/python3env/lib/python3.4/site-packages:/home/production_code/school
# WSGIProcessGroup application
use:
WSGIDaemonProcess application python-path=/home/production_code/python3env/lib/python3.4/site-packages:/home/production_code/school
WSGIProcessGroup application
WSGIApplicationGroup %{GLOBAL}
A key part of this is the WSGIApplicationGroup directive, with it being set to %{GLOBAL}.
This is to get around faulty third party extension modules for Python that don't work in sub interpreters and which can fail with a dead lock or crash.
See:
https://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API
It is also recommend you go back to using daemon mode. It is generally not a good idea to use embedded mode.
http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html