Django Apache and name-based VirtualHost - django

I have recently locally deployed Django project on Apache server Fedora 36. Everything work good when accessing site by ip. The issue that could not access it by hostname. I am getting "Bad Request (400)" error.
here my httpd.conf
<VirtualHost *:80>
ServerName calljournal.local
alias /static /var/www/django_project/call_journal/static
<Directory /var/www/django_project/call_journal/static>
Require all granted
</Directory>
<Directory /var/www/django_project/call_journal>
Require all granted
</Directory>
WSGIDaemonProcess calljournal.local python-path=/var/www/django_project/virt/lib/python3.8/site-packages
WSGIProcessGroup calljournal.local
WSGIScriptAlias / /var/www/django_project/call_journal/call_journal/wsgi.py
redirect / https://192.168.1.109
</VirtualHost>
and my hosts file
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.109 calljournal.local

You need to enter the hostname in ALLOWED_HOSTS settings.

Related

Having Issue Adding Site to Local Host Virtual Host

Using WampServer 2.4.41 on Win64 Apache I am using this setting in my httpd-vhosts.confbust this is adding the maper as a new VirtualHost to the WampServer instead of adding it as Site into localhost:8080 VirtualHost
<VirtualHost *:8080>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
#webematics
<VirtualHost *:8080>
ServerName maper
ServerAlias maper
DocumentRoot "${INSTALL_DIR}/www/maper"
<Directory "${INSTALL_DIR}/www/maper/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
I also have the hosts as
#
127.0.0.1 localhost
::1 localhost
127.0.0.1 maper
As you can see the maper is listing on my projects but it is not click able and also I am getting this message
To use them as an http link, you must declare them as VirtualHost
What am I missing, and how can I fix this to put everything under one Virtual Host localhost?

how to make django render the default home page instead of apache

As is known, after issuing a request with a sole IP or server name through web explorer, apache will return its default static home page to the explorer. I'm using django and apache with mod_wsgi to deploy my site(i.e. django app on apache web server). How to route the processing to django mapping rules defined in views.py to dynamically produce a home page(i.e. index page) for that site when I issue a request to that server running apache? Thanks in advance!
I added the following configuration in the main Apache 'httpd.conf':
<VirtualHost 127.0.0.1:80>
ServerName 127.0.0.1
ServerAlias example.com
ServerAdmin webmaster#example.com
DocumentRoot /usr/local/www/documents
Alias /robots.txt /usr/local/www/documents/robots.txt
Alias /favicon.ico /usr/local/www/documents/favicon.ico
Alias /media/ /usr/local/www/documents/media/
<Directory /usr/local/www/documents>
Require all granted
</Directory>
WSGIDaemonProcess 127.0.0.1 processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup 127.0.0.1
WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi
<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Code in myapp.wsgi:
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
Then I issued 127.0.0.1, the explorer displayed 'It works!', which is the default page produced by apache, instead of which I wanted 'Hello world!' returned in this case. I just want that when just issued an IP or site address, the work of generating the default home page is directly delegated to django to dynamically handle rather than to return a static index.html by Apache. Although I configured WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi , this seems still not work.
Virtual hosts don't work in that way for 127.0.0.1 as it is treated a bit special. What is going to happen, unless that is the only VirtualHost in your configuration, is that Apache will fall back to using the first VirtualHost definition it found, usually the default site.
So normally you would have:
<VirtualHost *:80>
ServerName my.fqdn.host.name
...
</VirtualHost>
That is, no IP in VirtualHost directive and ServerName is the actual hostname that appears in the URL, not an IP address.
Was there a prior VirtualHost in httpd.conf or was it including including extra/httpd-vhosts.conf, that would result in a VirtualHost superseding this one?

How do I receive subdomain wildcards on Apache2 using mod wsgi?

I'm developing an app with Django 1.8 and I'm trying to receive subdomains and then present customized homepages dependent on the subdomain. For example: example.com is my company's homepage, a user signs up as conqueryor.example.com and they get a new homepage named "conqueryor.example.com" or whatever they want.
Sounds simple enough, there's even the django subdomains library that I'm using. My current issue lies in setting up Apache2 and mod WSGI locally so that I can test it out locally before I affect everyone else on the project. I'm currently able to use the following .conf file with the lines 127.0.0.1 example.dev and 127.0.0.1 .example.dev in my /etc/hosts file. In my browser I'm able to access my app from example.dev, but if I try any subdomains I receive the Server Not Found page. I've also attempted using dnsmasq and adding the line address=/.example.dev/127.0.0.1
Current environment:
Ubuntu 15.10
Django 1.8.1
Apache 2.4
<VirtualHost *:80>
ServerName example.dev
DocumentRoot /home/example
ServerAlias www.example.dev
WSGIDaemonProcess example python-path=/home/example:/home/venv/example/lib/python2.7/site-packages
WSGIProcessGroup example
WSGIScriptAlias / /home/example/saas/wsgi.py
<Directory /home/example/static>
Require all granted
</Directory>
<Directory /home/example/saas>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName example.dev
DocumentRoot /home/example
ServerAlias example.dev
WSGIDaemonProcess example2 python-path=/home/example:/home/venv/example/lib/python2.7/site-packages
WSGIProcessGroup example2
WSGIScriptAlias / /home/example/saas/wsgi.py
Alias /static/ /home/example/static/
<Directory /home/example/static>
Require all granted
</Directory>
<Directory /home/example/saas>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName example.dev
DocumentRoot /home/example
ServerAlias *.example.dev
WSGIDaemonProcess example3 python-path=/home/example:/home/venv/example/lib/python2.7/site-packages
WSGIProcessGroup example3
WSGIScriptAlias / /home/example/saas/wsgi.py
Alias /static/ /home/example/static/
<Directory /home/example/static>
Require all granted
</Directory>
<Directory /home/example/saas>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Thanks!
I'm going to leave the question in case this helps anyone else, but I found the solution... I forgot I hadn't restarted dnsmasq, so after adding the address=/.example.dev/127.0.0.1 line to /etc/dnsmasq.conf and restarting dnsmasq with sudo /etc/init.d/dnsmasq restart I was able to access sites on subdomains. Oops!

going to www version of site url receives 404 on django site

I can get to the route of my site without issues like this: http://example.com
When I go to http://www.example.com I get a 404 error.
How can I handle going to www and delivering the user to the route of the site?
I don't think it is related, but here is my httpd.conf:
WSGISocketPrefix /var/run/wsgi
<VirtualHost *:80>
WSGIDaemonProcess example.com display-name=%{GROUP}
WSGIProcessGroup example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /example
WSGIScriptAlias / /example/wsgi.py
</VirtualHost>
Alias /static/ /example
<Directory /example>
Order deny,allow
Allow from all
</Directory>
WSGIPythonPath /example
<Directory /example>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
Change ALLOWED_HOSTS in the settings.py to something like this
ALLOWED_HOSTS = ['www.example.com', 'example.com']
According to Django Documentation, ALLOWED_HOSTS defines
A list of strings representing the host/domain names that this Django site can serve. This is a security measure to prevent an attacker from poisoning caches and triggering password reset emails with links to malicious hosts by submitting requests with a fake HTTP Host header, which is possible even under many seemingly-safe web server configurations.
For more ALLOWED_HOSTS

access from another pc on lan network to django apache

Greetings and sorry for the english ..
I have the following problem and would appreciate if you can help me solve it:
I have set up django with apache and sample site by my email which is geounl.api/admin which resolved without any problem on my computer, but want to access from another PC connected to the same network I can not find the site ..
settings of my hosts is:
127.0.0.1 test.djangoserver
127.0.0.1 edgar-PC.edgar.com edgar-PC
127.0.1.1 prueba.djangoserver**
192.168.0.103 geounl.api -----------> ip address of my pc
and my virtualhots is:
<VirtualHost *:80>
ServerName geounl.api
DocumentRoot /home/edgar/Django/GeoUnl
<Directory /home/edgar/Django/GeoUnl >
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess geounl.api processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup geounl.api
WSGIScriptAlias / /home/edgar/Django/GeoUnl/apache/django.wsgi
Alias /static/ /home/edgar/Django/prueba/static/
<Directory /home/edgar/Django/prueba/static/>
Order deny,allow
Allow from all
</Directory>
Thanks and I hope your help