I'm trying to serve two Django projects on different virtualenv at the same IP adress on Apache.
My first site is at http://myip/site-1
and the seccond: http://myip/site-2
When I run http://myip/site-1, Apache serves it without issues, but when I run the second (http://myip/site-2) it raises the following:
The requested URL /site-2/ was not found on this server.
Because it searches in the first site's document root.
Here is my apache.conf
<VirtualHost *:80>
ServerName site-1.example.com
DocumentRoot /home/venv/site-1
# adjust the following line to match your Python path
WSGIDaemonProcess site-1.example.com processes=2 threads=15 display-name=%{GROUP} python-home=/home/venv/lib/python2.7
WSGIProcessGroup site-1.example.com
WSGIScriptAlias / /home/venv/site-1/site-1/wsgi.py
<directory /home/venv/site-1>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/venv/site-1/static_root/
<Directory /home/venv/site-1/static_root>
AllowOverride all
Require all granted
Options FollowSymlinks
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName site-2.example.com
DocumentRoot /home/venv_mob/site-2
# adjust the following line to match your Python path
WSGIDaemonProcess site-2.example.com processes=2 threads=15 display-name=%{GROUP} python-home=/home/venv_mob/lib/python2.7
WSGIProcessGroup site-2.example.com
WSGIScriptAlias / /home/venv_mob/site-2/site-2/wsgi.py
<directory /home/venv_mob/site-2>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/venv_mob/site-2/static_root/
<Directory /home/venv_mob/site-2/static_root>
AllowOverride all
Require all granted
Options FollowSymlinks
</Directory>
</VirtualHost>
I have tried many solutions that I found on the web but the problem remains the same.
Any ideas ?
You have to connect to http://site-1.example.com (using terms from your example), not http://myip/site-1. And http://site-2.example.com, not http://myip/site-2.
Generally speaking you can have name-based virtual hosts for which you need to configure DNS (mapping site-1.example.com and site-2.example.com to your IP address) or you can run different sites on different ports.
Related
I have multiple django projects and i want to host them under same domain
eg: example.com/one<br> example.com/two
I have searched for various solutions and found the below given link which helped me alot.
Is it possible to host multiple django projects under the same domain?
From the above reading , I get to know that I need mod_wsgi for this but I am confused that where to install this mod_wsgi - Do i need to install under every project folder (seperate for every myenv) or it should be installed only once .
Please help me in how and where to install this mod_wsgi and finally how to host multiple projects under same domain name.
Some Code Tried By Another User With Same Problem But Also Not Working
<VirtualHost *:80>
ServerAdmin admin#my_domain.com
ServerName my_domain.com
ServerAlias www.my_domain.com
DocumentRoot /var/www/my_domain.com
ErrorLog ${APACHE_LOG_DIR}/my_domain.com_error.log
CustomLog ${APACHE_LOG_DIR}/my_domain.com_access.log combined
# site_1
Alias /site_1_project/static /var/www/my_domain.com/site_1_project/static
<Directory /var/www/my_domain.com/site_1_project/static>
Require all granted
</Directory>
Alias /site_1_project/media /var/www/my_domain.com/site_1_project/media
<Directory /var/www/my_domain.com/site_1_project/media>
Require all granted
</Directory>
<Directory /var/www/my_domain.com/site_1_project/site_1_project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess site_1_project python-path=/var/www/my_domain.com/site_1_project python-home=/var/www/my_domain.com/site_1_project/django_env_site_1
WSGIProcessGroup site_1_project
WSGIScriptAlias /site_1_project/ /var/www/my_domain.com/site_1_project/site_1_project/wsgi.py
# site_2
Alias /site_2_project/static /var/www/my_domain.com/site_2_project/static
<Directory /var/www/my_domain.com/site_2_project/static>
Require all granted
</Directory>
Alias /site_2_project/media /var/www/my_domain.com/site_2_project/media
<Directory /var/www/my_domain.com/site_2_project/media>
Require all granted
</Directory>
<Directory /var/www/my_domain.com/site_2_project/site_2_project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess site_2_project python-path=/var/www/my_domain.com/site_2_project python-home=/var/www/my_domain.com/site_2_project/django_env_site_2
WSGIProcessGroup site_2_project
WSGIScriptAlias /site_2_project/ /var/www/my_domain.com/site_2_project/site_2_project/wsgi.py
#RewriteEngine on
#RewriteCond %{SERVER_NAME} =my_domain.com [OR]
#RewriteCond %{SERVER_NAME} =www.my_domain.com
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Installing mod_wsgi depends on what your host OS is. Check the instructions. If you're using CentOS or RedHat, I'd recommend looking at IUS Community; they provide a repository with yum installable packages for Python 3.6 and mod_wsgi. The version of mod_wsgi you install has to be compiled against the same version of Python you are running into your virtual environment.
Then you need to configure your VirtualHost properly. If you have a host at the root, it has to come last in your definition. Here's an example:
<VirtualHost *:443>
TimeOut 300
SSLEngine On
ServerName mysite.example.com
# Set to the lobal Application Group
WSGIApplicationGroup %{GLOBAL}
# Pass Authorizations through to the WSGI app for Django REST Framework Token Auth
WSGIPassAuthorization On
WSGIDaemonProcess subsite-develop-https python-home=/web/subsite-develop/venv request-timeout=300 user=apache group=apache
WSGIProcessGroup subsite-develop-https
WSGIScriptAlias /subsite /web/subsite-develop/config/wsgi.py process-group=subsite-develop-https
<Directory /web/subsite-develop/config>
Require all granted
</Directory>
Alias /subsite/static/ /web/subsite-develop/static/
<Directory /web/subsite-develop/static>
Header always set Access-Control-Allow-Origin "*"
Require all granted
</Directory>
WSGIDaemonProcess django-mysite-develop-https python-home=/web/django-mysite-develop/venv request-timeout=300 user=apache group=apache
WSGIProcessGroup django-mysite-develop-https
WSGIScriptAlias / /web/django-mysite-develop/config/wsgi.py process-group=django-mysite-develop-https
<Directory /web/django-mysite-develop/config>
Require all granted
</Directory>
Alias /static/ /web/django-mysite-develop/static/
<Directory /web/django-mysite-develop/static>
Header always set Access-Control-Allow-Origin "*"
Require all granted
</Directory>
Alias /media/ /var/media/mysite-www/
<Directory /var/media/mysite-www>
Require all granted
</Directory>
</VirtualHost>
This example will host one site at /subsite/ and another at the root, /. Notice that the root site comes last. It also means that you won't be able to use the route /subsite/ within the root project, since Apache will have diverted it to via the WSGIScriptAlias definition.
This is also for a site with TLS; you may have to switch the 443 to 80, and remove SSLEngine On if you're not using TLS. The WSGIPassAuthorization is for Django REST Framework tokens, you can probably remove it as well, but I've left it for a more complete example. This is for Apache 2.4+, when they switched to the Require all granted syntax.
IUS Community, if on RedHat/CentOS: https://ius.io/
I'll tell you how we did in our project. We have a single Django project with different routes. For example /players, /tablet. We hosted our project in two Docker containers. We have NGINX as our reverse proxy. NGINX redirects the request to the appropriate container based on the route. NGINX is exposed to the world. But, I'm not sure if it is useful for you or not.
Getting 403 Forbidden when attempting to send requests to my Flask app.
Finding a lot of examples of this error online but none of the solutions work for me so far.
Error from the apache error log file:
AH01630: client denied by server configuration: /opt/MyTinyURL/webtool.wsgi
Here is my VirtualHost.
<VirtualHost *:80>
ServerName MY_SERVER_NAME
DocumentRoot /opt/MyTinyURL
WSGIDaemonProcess webtool user=www-data group=www-data threads=5 home=/opt/MyTinyURL/
WSGIScriptAlias / "/opt/MyTinyURL/webtool.wsgi"
<Directory "/opt/MyTinyUrl">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride None
Require all granted
WSGIProcessGroup webtool
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
</Directory>
</VirtualHost>
UNIX file path names are case sensitive. The path used with WSGIScriptAlias doesn't match that used in the Directory directive.
Cleaning up a few other issues with things that aren't needed, try using:
<VirtualHost *:80>
ServerName MY_SERVER_NAME
# XXX Bad practice to set DocumentRoot to be directory
# where your code is. Comment out WSGIScriptAlias and
# people could download your source code.
# DocumentRoot /opt/MyTinyURL
# XXX Don't need user/group as the default to Apache user.
WSGIDaemonProcess webtool threads=5 home=/opt/MyTinyURL/
WSGIScriptAlias / "/opt/MyTinyURL/webtool.wsgi"
# XXX You had MyTinyUrl and not MyTinyURL.
<Directory "/opt/MyTinyURL">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride None
Require all granted
WSGIProcessGroup webtool
WSGIApplicationGroup %{GLOBAL}
# XXX Script reloading is the default option.
# WSGIScriptReloading On
</Directory>
</VirtualHost>
I have set up an ec2 instance and I'm able to connect to it via ssh. I've installed apache, django, git and all the necessary dependencies.
I've managed to clone a git repository which is located in /home/ubuntu/.
I've also set up the configuration file in /etc/apache2/sites-enabled/hyper-blog.conf.
This is my hyper-blog.conf file:
<VirtualHost *:80>
ServerName ec2-52-11-240-28.us-west-2.compute.amazonaws.com
ServerAlias ec2-52-11-240-28.us-west-2.compute.amazonaws.com
ServerAdmin webmaster#localhost
DocumentRoot /home/ubuntu/hyper-blog/
AddDefaultCharset UTF-8
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
alias /static/ /home/ubuntu/hyper-blog/static/
alias /media/ /home/ubuntu/hyper-blog/media/
<Directory "/home/ubuntu/hyper-blog/static">
Require all granted
Options -Indexes
</Directory>
<Directory "/home/ubuntu/hyper-blog/media">
Require all granted
Options -Indexes
</Directory>
<Directory /home/ubuntu/hyper-blog/hyper-blog>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
#RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.hyperiondev.com%{REQUEST_URI}
WSGIDaemonProcess hyper-blog python-path=/home/ubuntu/hyper-blog:/usr/local/lib/python3.4/dist-packages
WSGIProcessGroup hyper-blog
WSGIScriptAlias / /home/ubuntu/hyper-blog/hyper-blog/wsgi.py
The problem is when I go to my public domain: ec2-52-11-240-28.us-west-2.compute.amazonaws.com it takes a while to load and eventually does not render anything.
I need to know how to get my application up and running. I've tried this documentation on digital ocean https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04,
but still doesn't work.
How can I get my application working without installing virtualenv?
Unable to access django projects' named server after deploying on apache virtual host.
Below is the tag snippet that I have came up with.
Listen 8000
<VirtualHost *:8000>
DocumentRoot "/var/www/ecomgroup/ecom/ecomstore-8000"
ServerName fpshoppingfashionpassion.com
ServerAdmin webmaster#localhost
Alias /static /var/www/ecomgroup/ecom/ecomstore/public/static
<Directory /var/www/ecomgroup/ecom/ecomstore/public/static>
Require all granted
</Directory>
<Directory /var/www/ecomgroup/ecom/ecomstore/ecomstore/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess econroot.com python-path=/var/www/ecomgroup:/var/www/ecomgroup/venv/lib/python2.7/site-packages
WSGIProcessGroup econroot.com
WSGIScriptAlias / /var/www/ecomgroup/ecom/ecomstore/ecomstore/wsgi.py
</VirtualHost>
Please let me know if something else goes here.
I'm having an issue configuring mod_wsgi with Apache 2.2. I need mod_wsgi to handle everything under root directory of a virtual server except certain paths. For those paths I want ordinary Apache directory listing to work. The following virtual server config half works. mod_wsgi does not kick in for paths directly to files but does for directories. I can't figure this out. Looked at docs here - https://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide. It shows using aliases in the way I have to disable mod_wsgi but does not mention this problem. (Note not that it matters but the foo.wsgi end point is just the hello world example).
<VirtualHost *:80>
ServerAdmin webmaster#test.wsgi.sethandler.localdomain
ServerName test.wsgi.sethandler.localdomain
DocumentRoot /var/www/test.wsgi.sethandler.localdomain
<Directory /var/www/test.wsgi.sethandler.localdomain>
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo Options Indexes
Order allow,deny
allow from all
</Directory>
Alias /static /var/www/test.wsgi.sethandler.localdomain/static
WSGIScriptAlias / /var/www/test.wsgi.sethandler.localdomain/cgi-bin/foo.wsgi
<Directory /var/www/test.wsgi.sethandler.localdomain/cgi-bin>
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
I've tried disabling any handler with the following but it does not work:
<Location "/static">
SetHandler None
</Location>
<LocationMatch ^/static>
SetHandler None
</LocationMatch>
Have you tried putting and end slash after static?
Alias /static/ /var/www/test.wsgi.sethandler.localdomain/static/
<Directory /var/www/test.wsgi.sethandler.localdomain/static/>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/test.wsgi.sethandler.localdomain/cgi-bin/foo.wsgi