Django two websites hosted with Apache, urls do not work at one of them - django

I did set up two websites (hosted locally). I'm on windows so config may look odd.
WSGIPythonHome "C:/var/www/magazyn/env39"
WSGIPythonPath "C:/var/www/magazyn/venv/Lib/site-packages;C:/var/www/magazyn/rootkat/"
ServerName www.magazyn-stolarz.pl
LoadFile "C:/Python39/python39.dll"
LoadModule wsgi_module "C:/var/www/magazyn/env39/lib/site-packages/mod_wsgi/server/mod_wsgi.cp39-win_amd64.pyd"
WSGIScriptAlias /awizacje "C:/var/www2/awizacje/rootkat/awizacje/wsgi.py"
WSGIScriptAlias / "C:/var/www/magazyn/rootkat/magazyn/wsgi.py"
<Directory "C:/var/www2/awizacje/rootkat/awizacje/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /statica "C:/var/www2/static/"
<Directory "C:/var/www2/static/">
Require all granted
</Directory>
<Directory "C:/var/www/magazyn/rootkat/magazyn/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static "C:/var/www/static/"
<Directory "C:/var/www/static/">
Require all granted
</Directory>
With that configuration base site works perfectly ("pc-name/") but the second one ("pc-name/awizacje") does not. Main url works like it should but every button sends me to ("pc-name/button-url") and not ("pc-name/awizacje/button-url"). I have set ROOT_URLCONF = 'awizacje.urls' in settings.py. Is there something I am missing? Any way I should change settings to take base url into account?

The problem were hardcodded urls. I changed it so it will use django urls into account.

Related

Django for windows, using WSGIPythonPath for multiple instances of Virtual Host

Im using Windows 10
In httpd.conf (Apache) how to use WSGIPythonPath for multiple instances of Virtual Host for different project and ports since WSGIDaemonProcess is not supported on Windows.
httpd.conf
LoadModule wsgi_module "c:/users/webdev/documents/mark/digos-logs/venv/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "C:\Users\WebDev\AppData\Local\Programs\Python\Python37"
WSGIPythonPath "C:\Users\WebDev\Documents\Mark\digos-logs"
where "C:\Users\WebDev\Documents\Mark\digos-logs" is my project root folder and "C:\Users\WebDev\Documents\Mark" is my parent folder of all my projects.
Project 1
listen 9292
<VirtualHost *:9292>
ServerName 127.0.0.1
# error occured (Example)
WSGIPythonPath "C:\Users\WebDev\Documents\Mark\digos-logs"
######3
WSGIScriptAlias / "C:\Users\WebDev\Documents\Mark\digos-logs\app_ict\wsgi.py"
<Directory "C:\Users\WebDev\Documents\Mark\digos-logs\app_ict">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
DocumentRoot C:\Users\WebDev\Documents\Mark\digos-logs
<Directory "C:\Users\WebDev\Documents\Mark\digos-logs\static">
Require all granted
</Directory>
</VirtualHost>
Project 2
listen 9595
<VirtualHost *:9595>
ServerName 127.0.0.1
# error occured (Example)
WSGIPythonPath "C:\Users\WebDev\Documents\Mark\project2"
######3
WSGIScriptAlias / "C:\Users\WebDev\Documents\Mark\project2\app\wsgi.py"
<Directory "C:\Users\WebDev\Documents\Mark\project2\app">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
DocumentRoot C:\Users\WebDev\Documents\Mark\project2
<Directory "C:\Users\WebDev\Documents\Mark\project2\static">
Require all granted
</Directory>
</VirtualHost>

Default Apache displaying instead of homepage

I am having issues trying to deploy my site,.I am still new in both Django , their is a tutorial I have been following on how to deploy the site, Everything works fine except it renders the default Apache page instead of my site when I restart the server.
Here is my project directory
Alias /static /home/brian/src/static
<Directory /home/brian/src/static>
Require all granted
</Directory>
Alias /media /home/brian/src/media
<Directory /home/brian/src/media>
Require all granted
</Directory>
<Directory /home/brian/src/src>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/brian/src/src/wsgi.py
WSGIDaemonProcess django_app python-path=/home/brian/src python-home=/home/brian/src/venv
WSGIProcessGroup django_app

Django - permission denied

I'm trying to setup Django (Django 1.9.6) on Apache (Apache 2.4.10) in my vps (ubuntu server 15.04).
I followed this guide: HERE
Unfortunately when I try to visit my website, the server return this error (403 Forbidden):`
[authz_core:error] AH01630: client denied by server configuration: /home/user/proj/proj/wsgi.py
I searched everywhere for a solution but everything I tried didn't work.
this is my /etc/apache2/sites-available/000-default.conf file:
Alias /static /home/user/proj/Gestione/static
<Directory /home/user/proj/Gestione/static>
Order deny,allow
Allow from all
</Directory>
<Directory /home/user/proj/proj>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIDaemonProcess proj python-path=/home/user/proj:/home/user/.local/lib/python3.4/site-p$
WSGIProcessGroup proj
WSGIScriptAlias / /home/user/proj/proj/wsgi.py
Then i found this code on /etc/apache2/apache2.conf, I don't know if this could create problems:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
This is my wsgy.py:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proj.settings")
application = get_wsgi_application()
I'm NOT using virtualenv
Thanks for help
In Apache 2.4, you should use Require all granted instead of Order deny,allow and Allow from all.
It looks like you are using the old style in two places in 000-default.conf. Try updating it to:
<Directory /home/user/proj/Gestione/static>
Require all granted
</Directory>
<Directory /home/user/proj/proj>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

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!

django- deploy with mod_wsgi css not showing

I am using libapache2-mod_wsgi for deploying my django app. I wrote httpd.conf as follows:
Alias /static/ /home/ubuntu/similarkind/similarkind/static/
<Directory /home/ubuntu/similarkind/similarkind/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /home/ubuntu/similarkind/similarkind/wsgi.py
WSGIPythonPath /home/ubuntu/similarkind:/home/ubuntu/pysushu/lib/python2.7/site-packages
<Directory /home/ubuntu/similarkind/similarkind>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
Well my app is working just fine but css and javascript is not showing up.
I have my css and js in static folder. Also my directory structure for app looks like
/similarkind
/static
/foundation-3
/stylesheets
/js
/jquery-ui
/css
/js
Can anyone tell what thing am I missing?