multiple domains, multiple django projects, one server - django

Hi I'm new to apache and mod_wsgi and am trying to figure out how to configure both so that i can have www.example1.com use djangoproject1 and www.example2.com use djangoproject2.
I followed this tutorial to hook up example1.com to djangoproject1 and it works beautifully, but the tutorial doesn't exactly give the most detailed explanations for what is going on and why i need to do certain things.
what i have so far:
1) a dns zone for example2.com pointing to the server ip
2) installed python environment and django and started a new django project for djangoproject2 per the instuctions on the tutorial
I'm pretty sure i'm going to have to create a new wsgi config file and add a site configuration in /etc/apache2/sites-available/ called example2.com and then enable it, but i'm not sure about what else i'd need to do.

You can have 2 virtual hosts in your apache configuration.
The first virtual host on (default) - port 80
second one on port 81
In the virtual host, you can specify it this way:
NameVirtualHost *:80
<VirtualHost *.80>
DocumentRoot django_project_1_path
.... other config
WSGIScriptAlias / path_to_wsgi_config_1
</VirtualHost>
NameVirtualHost *:81
<VirtualHost *.81>
DocumentRoot django_project_2_path
.... other config
WSGIScriptAlias / path_to_wsgi_config_2
</VirtualHost>

Related

How to setup port to subdomain in AWS?

I have a domain (e.g. example.com) registered with godaddy.com and use AWS for hosting.
Nameserver on Godaddy later added to AWS
I have an ubuntu (t2.medium) apache server installed. My project in Docker has LAMP, ELK, Node, React, and Postgres installed. Everything works on the local system using direct ports. Few ports open in my project i.e.
example.com:3000 react app [frontend]
example.com:5601 kibana app
example.com:5050 postgradmin app
example.com/radius php applicatinn [backend]
example.com:8080 phpmyadmin app
my desired URLs are:
example.com:3000 react app [frontend] => http://example.com
example.com:5601 kibana app => http://kibana.example.com
example.com:5050 postgradmin app => http://postgradmin.example.com
example.com/radius php applicatinn [backend] => http://example.com/radius
example.com:8080 phpmyadmin app => http://phpmyadmin.example.com
I have tried a few things but nothing is working. on route53
tried reverse proxy on apache by adding separate conf files e.g.
default.conf
<VirtualHost *:80>
ServerAdmin contact#example.com
DocumentRoot "/var/www/html"
ServerName example.com
<Directory "/var/www/html/">
AllowOverride all
</Directory>
</VirtualHost>
kibana.conf
Listen 5601
<VirtualHost *:5601>
ServerAdmin contact#example.com
ServerName kibana.example.com
</VirtualHost>
pgadmin.conf
Listen 5050
<VirtualHost *:5050>
ServerAdmin contact#example.com
ServerName pgadmin.example.com
</VirtualHost>
when I run docker-compose up on EC2, http://example.com/radius works fine. but others do not (e.g. http://kibana.example.com). but if try with port directly (e.g. example.com:5601) it's working. but I want to use a sub-domain not a domain with a port.
How to do that?
reverse proxy I tried as mentioned in the description but it's not working properly
First, if you want your domains to be publicly accessible. You need to create records for all domains.
Second, if you want to access by only domains without port, you should create multiple blocks of virtual host listening to only port 80, and then do the routing base on domains your server received
Example can be found here

How to deploy NuxtJs Application on Apache and access it with IP-URL instead of a domain?

Please note, this is my first nuxt-app trying to deploy on a staging server. We have a staging AWS server where many web applications are deployed as follows.
http://0.0.0.0/app1/public (Laravel)
http://0.0.0.0/app2 (static)
http://0.0.0.0/app3/public/api (Lumen)
http://0.0.0.0/app4/public (VueJs Static)
etc
http://0.0.0.0/app5 (Tried NuxtJs Universal SSR) failed
Note: SERVER: AWS instance has Ubuntu 18.04 with apache2
Now I want to deploy NuxtJs Universal Application (SSR), I have studied many articles, tried but failed.
What I have done so far:
Moved my all code to /var/www/html/app5
followed all the steps https://nuxtjs.org/docs/2.x/deployment/deployment-pm2
stuck, what to do next, and don't know how to access it in a browser with IP server.
pm2 list, command gives me the following result.
Progress Update:
I have finally found a new way to configure it on the main IP with virtual host configuration:
<VirtualHost *:80>
ServerName http://0.0.0.0
DocumentRoot /var/www/html/app5
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
My steps to configure NuxtJs app on IP-URL:
Created a new virtual host as above named nuxtjs.conf
a2dissite 000-default.conf, it was pointing to /var/www/html
a2ensite nuxtjs.conf
a2enmod proxy_http and a2enmod proxy
systemctl restart apache2
Yahoo! my main server IP-URL (http://0.0.0.0) was pointed to NuxtJs-application running perfectly :-)
But the problem was my all other websites stopped because they were running with 000-default.conf virtual host.
Please guide, what should be configuration, I don't want to close my all websites, they should be running as I mentioned at the start as http://0.0.0.0/name-of-web. How can I run the NuxtJs application as ip-url/app-name?
After a long time, my question was alone, so I decided to give it a partner with my answer, part a joke I have found the solution, and the following is my finding. Please update it if you have the more appropriate knowledge.
Enabled 81 port via AWS console.
Added following configuration in the nuxt.config.js to run the application on a specific port locally in the server.
server: {
port: 43411
}
Updated virtual host as follows.
NameVirtualHost *:81
<VirtualHost *:81>
ServerName http://0.0.0.0
DocumentRoot /var/www/html/app5
ProxyPass / http://localhost:43411/
ProxyPassReverse / http://localhost:43411/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now I can access my nuxt-app on an IP URL as follows, along with all other deployed websites on this server.
http://0.0.0.0:81/

How to configure apache2 on ubuntu for django restful services

I have django restful services on my ubuntu server which are running on port 84.
When the request is send, it come through the apache2 server which is running on port 80.
Now let say my server ip is "xx.xx.xx.10" and when i call with this url http://xx.xx.xx.10/user where user is the rest service running on django rest framework on port 84. Then the request should go to my django rest service through apache2 and return the desired output.
I tried by using the below configuration in the apache2 :-
<VirtualHost *:80>
WSGIScriptAlias / /myproject/myapp/test/wsgi.py
<Directory "/myproject/myapp/test/">
<Files "wsgi.py">
Require all granted
</Files>
</Directory>
</VirtualHost>
but this is giving internal error saying that test.settings does not exits.
is this the right way to configure the restful services running on different port on apache server.
Did you specify a python path? If you don't, import mysite will not work.
WSGIPythonPath /path/to/mysite.com
For more info see: Django docs modWSGI
I have solved this issued by using the below configurations :-
<VirtualHost *:80>
ServerName mydomain
ServerAlias *.mydomain
ProxyRequests off
ProxyPass / http://localhost:84/
ProxyPassReverse / http://localhost:84/
</VirtualHost>

django apps on nginx running separately from apache

I am installing production server for my django apps and I can not make it work. My configuration files can be found here.
Basically I have apache2 installed and running on port 80 for my php applications. I want to run my django apps on nginx with uwsgi, apart from apache2. So I am running nginx on port 8000.
When I open http://IP:8000/ I can see my site properly.
1. But how do I set it up with domain name?
I've set A tag in dns to IP. Now it hits apache2 "it works" page because it hits port 80 on default? So I need to proxy pass all requests to my domain.com? Something like this?
/etc/apache2/sites-enabled/domain.com:
<VirtualHost *:80>
ServerName domain.com
ProxyPreserveHost On
ProxyPass / http://IP:8000
</VirtualHost>
It does not work, so how do I pass all domain requests from apache to nginx?
2. How do I add another domain name? (new app)
Do I just create new socket file for new app, keep it on port 8000 and nginx will decide depending on domain name what conf file to use?
I have not found any similar tutorials, nginx usually handles static files and sends requests to apache2. However I want it other way.
Thanks for your answer. To make it work I had to set apache proxy like this:
<VirtualHost *:80>
ServerName www.domain.com
ProxyPreserveHost On
ProxyPass /static http://XX.XX.XX.XX:8000/static
ProxyPassReverse /static http://XX.XX.XX.XX:8000/static
ProxyPass / http://XX.XX.XX.XX:8000
ProxyPassReverse / http://XX.XX.XX.XX:8000
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.(?!\.css|js|gif|png|jpg|ico))*$
RewriteRule /(.*) http://XX.XX.XX.XX:8000/$1 [P,L]
</VirtualHost>
and enable proxy_http:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo service apache2 restart
1. How do you set it up with domain name?
In the server block of your nginx conf file set the server_name:
server {
listen 8000;
server_name www.my-django-domain-one.foobar;
#rest of your config regarding forwarding to django...
}
Your site will be available at http://www.my-django-domain-one.foobar:8000.
2. How do you add another domain name? (new app)
Nginx will not decide anything based on the conf filename. Create a new conf file or use the existing one (only matters in the sense of how you want to organize your configs)
server {
listen 8000;
server_name www.my-django-domain-two.foobar;
#rest of your config regarding forwarding to django...
}
However, I recommend an approach involving only one web server. Opinions on which to use vary of course but both of them can do what you want to achieve on their own. You add unnecessary complexity to your setup (e.g. two servers to keep patched) and -depending on your traffic- it may even have a significant impact on your performance.
Check out this tutorial to see how you could make your php apps work with nginx and php-fpm.

403 forbidden when Django folder is located in /root

I'm trying to deploy my local Django site on my Ubuntu 12.04 server. I followed a tutorial, and everything seems to work fine, except Apache won't allow me to store my Django project under /root. More specifically, I get a 403 Forbidden when trying to access my site.
I suspect I need to configure my virtual host in a different manner. Any ideas?
Here is /etc/apache2/sites-available/mysite
<VirtualHost *:80>
ServerAdmin me#mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
WSGIScriptAlias / /root/me/index.wsgi
Alias /static/ /root/me/static/
<Location "/static/">
Options -Indexes
</Location>
ErrorLog /var/log/mysite/error.log
</VirtualHost>
Thanks for the comments. I'll mark this as the correct answer for future reference.
I ended up moving the whole Django project to /home/anotheruser, and defined DocumentRoot as per Aamir Adnans suggestion. After service apache2 restart it started working.