Issues getting Apache VirtualHost to properly Map - linux

I'm setting up a docker container on a linux server and I'm trying to set up a VirtualHost so that when I visit the domain I own it will show that website.
I have a DNS record on my domain to use the IP address of my linux server, and I installed apache on there to test and it worked properly.
If I start my container with
docker run -dit --name web-app -p 8080:80 web-image
I can go to mydomain.com:8080 and see my website, but it doesn't work if I just navigate to mydomain.com.
My VirtualHost stanza in httpd.conf is
<VirtualHost *:80>
ServerAdmin admin#mydomain.com
ServerName mydomain.com
ServerAlias mydomain.com
DocumentRoot /usr/local/apache2/htdocs
</VirtualHost>
The only thing I can think is that I need to update my domain DNS definition to accept the Docker Container IP address?
Is there something I'm missing?

It's quite obvious, that the website is available on port 8080, but not port 80, since you define -p 8080:80. You need to expose port 80 instead.
docker run -dit --name web-app -p 80:80 web-image

Related

Should I use domain name for my docker application instead of IP address?

I have a web application running in a Linux Ubuntu 20.04 (through docker) and I'm wondering if is valid use an alias for the users access this application.
Today they access using the server's IP (ex. 192.168.1.1) but the user are non-techs and I want mitigate the chances of error. By using a domain name (an alias), I think the chances of error are going to decrease.
I've no idea if is possible and if is a valid question xD.
Any thoughts will be really helpful.
It is preferable to use domain name for user applications.
Usually, instead of exposing a docker application directly to port 80/443, you'd setup a reverse proxy (gateway) in front of a docker application. Something like Apache or Nginx. You probably already have either of them on your current setup.
You just need to setup proper virtual host configurations.
For example, if you're using Apache:
<VirtualHost *:80>
DocumentRoot "/var/www/your/path"
# Assuming your domain name is internal.foobar.com
ServerName internal.foobar.com
# Assuming your docker application is binded to port 8080
ProxyPass "/" "http://127.0.0.1:8000/"
ProxyPassReverse "/" "http://127.0.0.1:8000/"
</VirtualHost>
If you're using Nginx:
server {
listen 80;
server_name internal.foobar.com;
root /var/www/your/path;
location / {
proxy_pass http://127.0.0.1:8000/;
}
}

Provision headers are shown error in google chrome when using apache virtual host

I have to tomcat servers running in my server. And I wanted to do a virtual host routing. So initially I tried it with one tomcat which is running in 8081 port and ajp port enabled to 8011 in the tomcat server.xml file
My conf file in the /etc/apache2/sites-available/mydomain_name.com.conf looks likes this
<VirtualHost *:80>
ProxyRequests off
ProxyPreserveHost On
ServerName mydomain_name.com
ServerAdmin ubuntu#mydomain_name.com
ProxyPass / ajp://localhost:8011/
ProxyPassReverse / ajp://localhost:8011/
</VirtualHost>
Then I did
sudo a2ensite mydomain_name.com.conf
sudo service apache reload
Every thing went find, no issues. And I also ensured the port 8011 is listening.
But when I try to access the server from my personal laptop, the request is blocked by Google chrome.
I have enabled these configurations in the server too.
sudo a2enmod proxy
sudo a2enmod proxy_ajp
sudo a2enmod proxy_http
sudo service apache2 restar
Have anyone has came across this issue ? Shedding some light would be really helpful. Because I have done some thing similar 1 year back, then this issue did not occur, and I'm only trying to direct it to the tomcat home page. Which is a bare minimal page.
After several frustrating hours found the issue. Hope this might help if any one came across this same issue.
Although the port 80 was opened via the aws management console security groups, internally the ports were firewall protected by the ip tables. So by removing the ip-tables entry for the port 80 I was able to make the virtual host work.

Hosting a MEAN app on Amazon EC2 - How to get domain name to link to my site?

Here's my situation: I followed this tutorial to host my website using Bitnami MEAN-Image on an Amazon EC2 instance - https://scotch.io/tutorials/deploying-a-mean-app-to-amazon-ec2-part-1. Then, I bought a domain name and set up my elastic IP address on my EC2 instance, and I've linked the domain and instance. If I run my app on port 3000 (npm start), I can see the app by going to mydomain.com:3000, but if I run my app on port 80, or if I don't run my app at all then I am taken to the default Bitnami MEAN page when I go to mydomain.com or mydomain.com:80. How do I get my app to appear on mydomain.com without specifying the port?
Editing to ask this; even without using my purchased domain name, is it possible to make my EC2 instance public dns default to my app's main page instead of defaultin to the Bitnami MEAN home-page?
If you have installed the Bitnami MEAN Stack, you will have your Apache server running on port 80, and it serves the default page located at /opt/bitnami/apache2/htdocs.
If you want Apache to serve your application by default, you can do it following the steps below:
Start your application in your port, for instance, the port 3000.
Go to your /opt/bitnami/apache2/conf/bitnami/bitnami.conf and add the following lines within your default Virtual Host configuration. It should look like this:
<VirtualHost default:80>
...
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
...
</VirtualHost>
Now, you should be able to access your application at http://your-ip/
You have to redirect your port 80 to 3000 so whenever they enter the domain or the ip, it gets to port 80.
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
use this and this should redirect the port 80 calls to 3000

apache virtual host subdomains is accessable only by localhost

i am try to make my pic.localhost virtual host accessible to public network(all of the internet)
now the problem is that it works only on the same machine in address pic.localhost but its not accessible even by lan network, only by the machine who runs it. what should i do?
i add and edited this files to make my pictures sub domain site:
1 - i included the httpd-vhosts file in my httpd.conf file.
2 - i added to httpd-vhosts file this lines:
<VirtualHost *:80>
ServerAdmin admin#domain
DocumentRoot "/opt/lampp/htdocs/"
ServerName pic.localhost
# ServerAlias www.pic.localhost
ErrorLog "logs/picture-error_log"
CustomLog "logs/picture-access_log" common
</VirtualHost>
3 - i added this line to /etc/hosts
127.0.0.1 pic.localhost
4 - i restarted the xampp server
i am running xampp 5.6.8 on Centos 7 machine.
Centos 7 has a firewall that by default blocks some ports (including port 80).
in the comand line, with sudo privileges try..
service firewalld stop
then in the terminal see you CENTOS LAN IP (ifconfig) and try to access that ip (ex 192.168.1.100).
if you are able to access the web-server. then try from another machine and in the browser tipe http://centos-lan-ip where centos-lan-ip is your centos machine IP.
Hope this works

pump.io port in URL

I just installed pump.io on my server (CentOS 6.5, x64), and I also have a Ghost blog (blog.mydomain.example) hosted on my server, which is behind Apache. The home page of my site is a static html page.
Now the problem is: when I visit social.mydomain.example, I'll be redirected to my blog (the URL is still social.mydomain.example). I can only visit pump.io by entering social.mydomain.example:31337 and the user link would be something like social.mydomain.example:31337/test. How can I make the port number disappear in the URL and visit pump.io via social.mydomain.example? Thanks!
Here are some configurations on my server:
Apache host settings:
<VirtualHost *:80>
ServerName blog.mydomain.example
ProxyPreserveHost on
ProxyPass / http://127.0.0.1:2368/
</VirtualHost>
<VirtualHost *:80>
ServerName mydomain.example
ServerAlias www.mydomain.example
ProxyRequests off
DocumentRoot /var/www/html
</VirtualHost>
How I installed pump.io
cd /usr/bin/nodejs/
git clone https://github.com/e14n/pump.io.git
cd pump.io
npm install
cd pump.io/node_modules/databank
npm install databank-mongodb
cd /usr/bin/nodejs/pump.io/bin
forever start pump
My pump.io configuration
cat /etc/pump.io.json
{
"driver": "mongodb",
"params": {"host": "localhost"},
"secret": "pumpiol",
"noweb": false,
"port": 31337,
"site": "social.mydomain.example",
"owner": "NetAdmin",
"ownerURL": "http://mydomain.example",
"hostname": "social.mydomain.example",
"nologger": false,
"serverUser": "pumpio",
"uploaddir": "/var/local/pump.io/uploads",
"debugClient": false,
"firehose": "ofirehose.example"
}
My iptables configuration
-A INPUT -m state --state NEW -m tcp -p tcp --dport 31337 -j ACCEPT
My DNS zone file:
A (Host)
Host Points To
# M.Y.I.P
CName (Alias)
Host Points To
blog #
social #
www #
OK since I got the badge of Tumbleweed, I'm encouraged to provide an answer.
For those like me who want a self-own microblogging service along with a blog, a home page (multiple sub-domains with one host server), while don't want the port number shown in the url, I recommend storytlr. It meet all my needs and it has been easily installed on a CentOS server (mine is 6.5, x64). The latest stable release is 1.20. Simple and direct.
What you're doing is running pump.io behind a web server. The simplest and recommended installation is to run pump.io standalone, if you have the extra IP address for it.
The other common way of running pump.io is to put it behind nginx. Apache is not as well suited to this kind of reverse proxying/websockets work. Many of us have started out trying pump.io behind Apache and switched to nginx because it's easier to configure and troubleshoot.
See http://jrobb.org/moving-my-pump-home.html or http://sjoberg.fi/blog/pumpio.html for examples.

Resources