How to configure subdomain to specific port - django

I have two projects 1: is wordpress running on apache (main website thespatio.com/45.33.10.149)
2: A Django Application running on Nginx using same IP with 81 port. (45.33.10.149:81). I want to configure above two apps so that when some one hit http://thespatio.com it should show main website and if some hit http://or.thespatio.com it should show my django application. I have seen many fix but none work for me. I tried virtual host like proxypass and proxy_reverse but apache stopped working. below are the two virtual hosts conf file
Main Website settings (conf)
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName thespatio.com
ServerAlias www.thespatio.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Django App (conf)
<VirtualHost *:80>
ServerAdmin admin#test.com
ServerName or.thespatio.com
ServerAlias www.thespatio.com
ProxyPass / http://or.thespatio.com:81/
ProxyPassReverse / http://or.thespatio.com:81/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Any help would be appreciated. Thanks in advance

mod_proxy was not installed. I follow Install mod_proxy tutorial and my both apps working fine.

Related

how to host multiple virtual hosts from same IP address in Apache server over AWS?

I want to host two different angular panels over Apache (AWS). So I disabled the default 000-default.conf file in etc/apache2/sites-available using a2dissite 000-default.conf and made two files webAdmin.conf and webUIpanel.conf. Now my webAdmin.conf has the following configuration
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UI/dist
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and webUIpanel.conf has following
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UserPanel/dist
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then I used a2ensite to enable both config files and at last sudo systemctl restart apache2. But one of them working at a time. I need to disable one to make other work. Kindly suggest me where did I go wrong?
You should add ServerName in your VirtualHost config so Apache can decide which site should get the request. So to apply that to your config it should look like:
webAdmin.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UI/dist
ServerName www.example1.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and webUIpanel.conf has following
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UserPanel/dist
ServerName www.example2.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
NOTE: Both ServerName should be valid domains so they resolve to your server or use your /etc/hosts file to point them to your server IP.

Domain and subdomains under one IP

I have a goal to host few websites as subdomains.(Apache2 at Ubuntu 18.04 at Google Cloud Platform)
Directories:
/var/www/domain.com/public_html- main directory for real registered domain
my subdomains
/var/www/test1.domain.com/public_html
/var/www/test2.domain.com/public_html
/var/www/test3.domain.com/public_html
Access to subdomains by address test(1,2,3).domain.com
I'm new with Apache2 so it's possibe I want something unreal or use Apache2 in wrong way. If so could you show my mistakes?
I tried to configure Virtual hosts but unsuccessful.
Maybe it is possible make it via htaccess?
domain.com.conf
<VirtualHost *:80>
ServerAdmin admin#mail.com
DocumentRoot /var/www/domain.com/public_html
ServerName domain.com
ServerAlias www.domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
test1.domain.com.conf
<VirtualHost *:80>
ServerAdmin admin#mail.com
DocumentRoot /var/www/test1.domain.com/public_html
ServerName test1.domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The trouble was not in Apache configuration. It was correct.
If you will have the same goal as mine, first of all you need
create subdomains at your domain registrar
create new A records under main domain in cloud DNS for each subdomain(Google Cloud Platform in my case)
wait (half hour in my case)
And only then configure Apache webserver.

How to redirect google VM external ip address to HTTPS in django with Debial and Apache?

I have successfully installed SSL certificate with certbot and lets encrypt on my debian and apache linux virtual machine on google cloud.
the domain is successfully secure with HTTPS.
Although on directly accessing the external ip address i am still getting an unsecure version of the website.
How to redirect the ip directly to the HTTPS version set up with APACHE and just the "domain.com" towards -->> HTTPs:www.domain.com .
I have tried to re-route to port 80 and 443 towards the HTTPS version as in PHP without any luck as shown here :
How to redirect from www to https www with htacces?
in my 000-default.conf:
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.bracketline.com [OR]
RewriteCond %{SERVER_NAME} =localhost
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI}
[END,NE,R=permanent]
</VirtualHost>
and on my 000-default-le-ssl.conf i have:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName localhost
ServerAdmin webmaster#localhost
Alias /static /var/www/static-root
<Directory /var/www/static-root>
Require all granted
</Directory>
Alias /media /var/www/media-root
<Directory /var/www/media-root>
Require all granted
</Directory>
<Directory /var/www/venv/src/cfehome>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess cfehome python-
path=/var/www/venv/src/:/var/www/venv/lib/python3.5/site-packages
WSGIProcessGroup cfehome
WSGIScriptAlias / /var/www/venv/src/cfehome/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerAlias www.bracketline.com
SSLCertificateFile
/etc/letsencrypt/live/www.bracketline.com/fullchain.pem
SSLCertificateKeyFile
/etc/letsencrypt/live/www.bracketline.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
I am not sure how this thing works if a detailed blog or turorial could be given it would be of great help. thanx in advance!
First lacate which .conf file youre actually using by typing apachectl -S (this works on Debian based OS'es).
Next up edit the file, it should look simillar:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
Protocols h2 http/1.1
# SSL Configuration
# Other Apache Configuration
</VirtualHost>
In general there are several tutorials how to configure HTTP to HTTPS redirect:
Redirect HTTP to HTTPS in Apache
How to Redirect HTTP to HTTPS on Apache
Apache Redirect to HTTPS
And some interesting discusson Why is my Apache VirtualHost directing to the wrong VirtualHost?
Lastly - here's another SO discussion on that topic that has an accepted answer.
Those are just recent (up to 2 years old) examples that will help you and there are dozens more if they won't answer your questions.

AWS ubuntu SSL installed but not loading https or http

I've followed exactly this youtube video tutorial to install SSL at my AWS Ubuntu Apache2 server. Youtube URL: https://www.youtube.com/watch?v=m06TttS2ZAM
Ubuntu version: Ubuntu 16.04.5 LTS
Apache version: Apache/2.4.18 (Ubuntu)
My domain name: pilefo.com
Here is the sites-enabled: 000-default.conf details:
<VirtualHost *:443>
ServerAdmin admin#pilefo.com
DocumentRoot /var/www/html
ServerName pilefo.com
ServerAlias www.pilefo.com
SSLEngine on
SSLCertificateFile /etc/ssl/certs/pilefo_com.crt
SSLCertificateKeyFile /etc/ssl/certs/pilefo.com.key
SSLCertificateChainFile /etc/ssl/certs/pilefo_com.ca-bundle
<Directory /var/www/html>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
#Redirect all http traffic to https
<VirtualHost *:80>
ServerName pilefo.com
ServerAlias www.pilefo.com
Redirect permanent / https://www.pilefo.com
</VirtualHost>
/etc/apache2/apache2.conf file details
link: https://textuploader.com/1avcv
Apache error log
https://textuploader.com/1avcn
https://textuploader.com/1avcn
Thanks in advance.

Django urls.py catches all existing HTML projects' urls on WampServer

I had WampServer working perfectly with Aptana IDE using multiple folders for different html projects. Then I installed Django and added this to Apache's httpd.conf:
Alias /images/ "c:/wamp/www/daas/templates/images/"
<Directory "c:/wamp/www/daas/images>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / "c:/wamp/www/daas/apache/django.wsgi"
<Directory "c:/wamp/www/daas/apache">
Allow from all
</Directory>
<VirtualHost *:80>
ServerName 127.0.0.1
DocumentRoot c:/wamp/www/daas/
</VirtualHost>
and now the virtual hosts I had for html projects...
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot 'C:\wamp\www'
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName projectA.local
DocumentRoot 'C:\wamp\www\projectA'
</VirtualHost>
don't load correctly because Django's urls.py is catching all urls The current URL, projectA, didn't match any of these regular expressions, even the ones not inside the Django's projects.
How can I solve this? On Djano's side or on Apache's side? Here (How do i run Django and phpmyadmin on apache webserver on ubuntu) is a similar problem but the solution didn't worked for me. And luckily localhost/phpmyadmin works correctly but localhost/projectA doesn't.
It looks like WSGIScriptAlias / "c:/wamp/www/daas/apache/django.wsgi" in your httpd.conf catches all requests on apache.