How to setup port to subdomain in AWS? - amazon-web-services

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

Related

Apache Reverse Proxy using mod_proxy

0 Introduction
I'm trying to setup a server with a main website hosted on ports 80 and 443 (let's call it example.com) and a section on this website that serves umami analytics hosted on port 3000 (let's call it umami.example.com) using a reverse proxy.
I'm using Django and Apache (with mod_wsgi as hinted from the django project) and I have to setup DNS using Cloudflare.
The main website works as intended, redirecting http traffic to https (more on that on the Apache section) and I'm tring to add this section under umami.example.com but every request ends up in a 404 error given by my main website.
Currently I'm trying to make the umami part work using a reverse proxy (as shown in the first section of the Apache Config)
####################################################################
1 DNS
DNS are configured using Cloudflare with 3 A records:
example.com -> server IP address
umami -> same server ip
www -> again same ip
and some MX and TXT ones.
####################################################################
2 Apache Config
<VirtualHost _default_:80>
ServerAdmin admin#example.com
ServerName umami.example.com
ProxyPass "/" "http://127.0.0.1:3000/"
ProxyPassReverse "/" "http://127.0.0.1:3000/"
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
Alias /static /mainfolder/static
DocumentRoot /mainfolder/django-folder
<Directory /mainfolder/django-folder/static>
Require all granted
</Directory>
<Directory /mainfolder/django-folder/django-app>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess django-folder python-path=/mainfolder/django-folder python-home=/usr/local/env
WSGIProcessGroup django-folder
WSGIScriptAlias / /mainfolder/django-folder/django-app/wsgi.py
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
####################################################################
3 What I've tried
Connecting directly to the IP address bypassing the DNS (port 80) makes no difference.
Connecting directly to the IP address bypassing the DNS (port 3000) works as intended.
Swapping places on the Apache Config works like this:
When the reverse proxy comes first (the config is as posted) then connecting to the 80 port serves the analytics website.
When the redirect comes first (swapped) connecting to the 80 port redirects to the HTTPS website
Adding and removing ProxyPreserveHost makes no difference.

apache configured but still website not loading coldfusion

I had the apache configured through web configuration tool. my coldfusion is installed on port 9000, but i want my websites to be run under apache,
so I followed the steps, created the webconfig in the coldfusion folder and matched the ports, in the httpd-vhosts.conf file
i wrote this
<VirtualHost *:8085>
DocumentRoot "C:/ColdFusion11/cfusion/wwwroot/project1"
ServerName test-host.corp.adobe.com
ServerAlias www.test-host.corp.adobe.com
ErrorLog "logs/test-host.corp.adobe.com.log"
CustomLog "logs/test-host.corp.adobe.com.log" common
JkMountFile "C:\ColdFusion11\config\wsconfig\1\uriworkermap.properties"
</VirtualHost>
i have xampp, so apache is configured on port 8085
but when i browse the website as:
test-host.corp.adobe.com or test-host.corp.adobe.com:8085, the page does not load, i tried restarting but no luck

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>

Route a specific path to a specific EC2 instance using Route 53

I'm not sure if this is even possible, but if so I'm looking for the best way to do it.
Say I want to host my blog for example.com on it's own EC2 instance, and I want the path to my blog to be example.com/blog
Is it possible to route all requests to example.com/blog/* to one instance, and all other requests to that domain elsewhere?
My web server is Apache.
Thanks!
You can now do this with Application Load Balancer and path-based routing: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/tutorial-application-load-balancer-cli.html#path-based-routing-aws-cli
Certainly it's possible, but not with DNS nor with an ELB. The most common solution to this is to use a web server that issues a 301 or 302 redirect.
In your case, example.com would point to whatever the main site is. The web server (nginx or Apache httpd, perhaps) hosting example.com would have a redirect for example.com/blog/* that is found at another destination.
Here's an SO post on using Nginx for a redirect and for using Apache for a redirect.
Yes, but you would have to proxy your requests through an instance handling example.com. How you configure this depends on your web server.
Some examples on how to configure this:
nginx: http://wiki.nginx.org/HttpProxyModule
Apache: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
Since you are using Apache2 Server, so you can achieve this very easily by creating a Virtual Host.
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/vchost1.com.conf
Create Virtual Configuration using the above command, it copies the complete code of content from the default file provided by the apache2 Server.
sudo nano /etc/apache2/sites-available/vchost1.com.conf
start configuring host & domain according to your requirements
<VirtualHost *:80>
ServerAdmin admin#domain.com
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
here also, you can multiple Virtual Host configurations in a single file, start configuring and enjoy hacking.
you can also multiple web applications in a single instance by using the same method and theis reference.
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04-quickstart

multiple domains, multiple django projects, one server

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>