I have an Ubuntu server in AWS that is running multiple application servers -- a Wildfly serving up some pages and two Tomcats running a separate app.
I am trying to get subdomains working.
I have DNS's set up to point subdomain1.example.com, subdomain2.example.com. That works fine.
Wildfly is listening on port 80 (I think?), the Tomcats are listening on 8080 and 8090. The goal is to have www.example.com go to Wildfly, subdomain1.example.com go to Tomcat : 8080 and subdomain2.example.com go to Tomcat : 8090
I've found numerous posts that talk about setting up virtual hosts in Apache that should solve my problem. But I keep getting sent down rabbit holes. Some suggest adding to /opt/bitnami/apache2/bin/httpd.config and some suggest putting it in /opt/bitnami/apache2/sites-available/subdomain1.example.com.conf
My first issue: I don't think that Apache is even running. I was under the impression that Apache was baked into Wildfly, but when I execute:
service apache2 status
I get:
apache2.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
Running sudo service --status-all also doesn't show it running so I think that it is not. It seems to be installed (Bitnami stack) in /opt/bitnami/apache2
Do I have to turn Apache on as part of Wildfly (and how to turn it on)? If I do, then I would assume that Wildfly is no longer getting traffic.
Second - my research tells me I need i need to enable proxy and proxy_http using a2enmod and a2ensite but I don't have these. Research suggests that all Ubuntu's will have those scripts... do they get created if I turn on Apache?
Sorry for all the noob questions.... I'm a developer without a DevOps guy. This seems like it would so common it would be baked in or there would be a definite solution that I am probably missing.
For those looking for something similar, here is the solution that worked for me.
My server is a Wildfly-Apache2-MySQL AMI image on AWS. I did not need to use a2enmod nor a2ensite as my research suggested. It seems many of those modules are already enabled by the pre-built image.
NOTE THESE INSTRUCTIONS ARE BITNAMI AWI SPECIFIC - YOUR FLAVOR CONFIGURATION MAY BE SLIGHTLY DIFFERENT
To have a subdomain point to a simple Apache text site (yada.example.com):
Create a directory in ~/stack/apache2/htdocs called yada
Add an entry to the virtual hosts configuration file (sudo nano /opt/bitnami/apache2/conf/extra/httpd-vhosts.conf)
<VirtualHost *:80>
ServerAdmin info#example.com
DocumentRoot "/opt/bitnami/apache2/htdocs/yada"
ServerName yada.example.com
ErrorLog "logs/yada-subdomain-error-log"
CustomLog "logs/yada-subdomain-access-log" common
</VirtualHost>
Modify the Apache configuration file to include the virtual hosts. (sudo nano /opt/bitnami/apache2/conf/httpd.conf):
...snip...
# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.
...snip...
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# ADDED THE ABOVE LINE
...snip...
Restart Apache (sudo /opt/bitnami/ctlscript.sh restart apache)
To make it point to a Tomcat server, add this to the httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin info#example.com
ServerName yada.example.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:8090/
ProxyPassReverse / http://localhost:8090/
</VirtualHost>
Your port may differ.
FYI, I found this helpful: https://docs.bitnami.com/virtual-machine/components/apache/#how-to-configure-your-web-application-to-use-a-virtual-host
Good luck and shout out to #stdunbar for his guidance.
Related
I can't figure how to create an SSL certificate for a Shiny server that runs on a CentOS machine.
My end goal is to be able to access my app with HTTPS.
So instead of - HTTP://mydomain.com:3838/my-app/
To have something like - HTTPS://mydomain.com:3838/my-app/
Or even better - HTTPS://mydomain/my-app/
I tried my best with numerous tutorials but I'm not an expert in system administration and didn't have a lot of success.
Would really appreciate any help here!
# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)
# shiny-server --version
Shiny Server v1.5.7.907
Thanks!
My answer in one word: letsencrypt.
Letsencrypt provides an executable that will grant you SSL certificates for all the domains your server handles. For this, it validates your machine by mounting a temporary web server and checks if can reach it with the domain names you provided.
There's more info in the official website. Once you have the certs, simply add them to nginx or Apache or whatever web server you are using.
UPDATE:
To forward http calls to your shiny web server you have to use Apache web server as a proxy, that means, that every call yo yourdomain:80, will be redirected to locahost:3838.
You have to edit your default conf. In ubuntu you can find it in this path: /etc/apache2/sites-enabled/000-default.conf
Then, in the conf file:
<VirtualHost *:80>
# These lines configures SSL
SSLEngine on
SSLCertificateFile /path/to/your/ssl.crt
SSLCertificateKeyFile /path/to/your/ssl.key
# These lines configure the proxy
ProxyPreserveHost On
ProxyPass / http://0.0.0.0:3838/
ProxyPassReverse / http://0.0.0.0:3838/
# This sets the domain name to listen for
ServerName yourdomain.com
</VirtualHost>
Then, restart apache and you're good to go.
This is for
Apache/2.4.7 (Ubuntu)
Ubuntu 14.04 LTS
I have a server with a certain IP address (example 22.22.22.22). I want to setup a DEV, a TEST and PROD environment.
for example if I go, from any computer in the world
1) to http://22.22.22.22 then I will hit the production website
2) to http://22.22.22.22/dev then I will hit the development website
3) to http://22.22.22.22/test then I will hit the testing website
How can I set this up?
Please share your suggestions and thoughts around this.
Thanks!
Not exactly what you asked for—I would take a slightly different approach. You will have a domain name, say example.com. You would have www.example.com and example.com point to your production site. Then you could have dev.example.com and test.example.com point to their respective sites. All of the DNS entries would still point to 22.22.22.22, but you would set up Apache to deal with them differently. This uses Apache named virtual hosts.
On the standard install of Apache, the site configurations should be in /etc/apache2/sites-available. To start with, there should be a configuration file named default. Create a new file prod with contents like the following:
# /etc/apache2/sites-available/prod
<VirtualHost 22.22.22.22:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/prod/html
(etc.)
</VirtualHost>
I've got the basics there, but you can look at the default for other directives you'll want there.
Next you create files for dev and test. Like so:
# /etc/apache2/sites-available/dev
<VirtualHost 22.22.22.22:80>
ServerName dev.example.com
DocumentRoot /var/www/dev/html
(etc.)
</VirtualHost>
It should be basically the same as prod, but different DocumentRoot and ServerName. The config for test will be almost the same too.
Once you have these set up, you just need to enable them. Run:
sudo a2ensite dev
...this enables dev. same thing again for test. After you run this, you should see the files are now also symlinked in /etc/apache2/sites-enabled. (The a2ensite command creates the symlink.)
Next, you just restart Apache. One way is: sudo service apache2 restart
I have an apache httpd server, say server1* (publicly exposed) that is acting as load balancer for some jboss servers(behind firewall) using mod_cluster. Now I want to install my static content (images/css/htmls) and probably some cg-scripts on a couple of apache servers, say **server2 and server3 (behind firewall).
Now I want server1 to act as load balancer for these server2 and server3 as well along with the jboss servers.
With this arrangement, any request for applications deployed on jboss need to be routed to jboss and any static content request should go to server2 or server3.
Here are the versions I am using
Linux Server
apache httpd - 2.2.22
JBOSS-EAP-6
What mechanism/configuration do I need to use in server1 to make it possible?
Please see if someone can help with this.
Well, you just add a ProxyPass setting. mod_cluster is compatible with ProxyPass, so you can use both.
For instance, if I would like gif images to be served by httpd, not by AS7, I can add:
ProxyPassMatch ^(/.*\.gif)$ !
Furthermore, if you set
CreateBalancers 1
mod_cluster won't create proxies for you and you have to do it yourself. This gives you an additional control. For instance:
ProxyPassMatch ^/static/ !
ProxyPass / balancer://qacluster stickysession=JSESSIONID|jsessionid nofailover=on
ProxyPassReverse / balancer://qacluster
ProxyPreserveHost on
In the aforementioned example, we proxy anything but /static/ content to the workers.
Note:If you encounter any cookies related issues, you might want to play with ProxyPassReverseCookieDomain and ProxyPassReverseCookiePath.
Note qacluster in my config. The default is mycluster, so for naming my balancer qacluster, I added this to mod_cluster config (outside VirtualHost):
ManagerBalancerName qacluster
If it is not clear, just reply and I can try to elaborate further.
I had the same issue where in we were using Apache HTTP server for static content and JBOSS AS 7 server for dynamic contents (the JSF web app).
So adding the below property at the end of Load modules tells
CreateBalancers 0
Tells to "0: Create in all VirtualHosts defined in httpd."
More at: http://docs.jboss.org/mod_cluster/1.2.0/html/native.config.html#d0e485
And the below config solved the issues of images and styel sheets not getting displayed.
<VirtualHost *:80>
ServerName dev.rama.com
DocumentRoot "/var/www/assests"
UseAlias 1
ProxyPassMatch ^(.*\.bmp)$ !
ProxyPassMatch ^(.*\.css)$ !
ProxyPassMatch ^(.*\.gif)$ !
ProxyPassMatch ^(.*\.jpg)$ !
ProxyPassMatch ^(.*\.js)$ !
ProxyPassMatch ^(.*\.png)$ !
<Directory /var/www/assests>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Note:
All our assests for the web app was on HTTP server at
/var/www/assests and the url I was accessing was dev.rama.com on port 80
So when it sees this ProxyPassMatch ^(.*.css)$ !
The webserver knows that the css files are local to the http server and we dont need to go to Jboss App server.
More info at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass
I have a VPS running CentOS 5. I want to point multiple domains at the same VPS (point them at the same IP), but serve up distinct websites for each domain.
So, the setup I want is like this:
site1.com ----> 127.0.0.1 ----> /var/www/html/site1.com/
site2.com ----> 127.0.0.1 ----> /var/www/html/site2.com/
I've tried setting up virtual hosts through the CentOS GUI for Apache, but they don't seem to be working. Only the first virtual host added will work (i.e. If I add site1.com first, both domains direct to that site. If I add site2.com first, both domains direct to that site.)
What might I be doing wrong? Is there an effective step-by-step tutorial for newcomers to get me started?
Update
Please remember, I have little to no experience working with CentOS and Linux ... but I'm learning.
To those who asked to see the directives I'm using, here's what CentOS added to the bottom of /etc/httpd/conf/httpd.conf when I used the built-in Apache GUI:
<VirtualHost skylarkapp.com:80>
DocumentRoot /var/www/html/skylarkapp.com
<Directory "/var/www/html/skylarkapp.com">
allow from all
Options +Indexes
</Directory>
ServerName skylarkapp.com
</VirtualHost>
<VirtualHost eamann.com:80>
DocumentRoot /var/www/html/eamann
<Directory "/var/www/html/eamann">
allow from all
Options +Indexes
</Directory>
ServerName eamann.com
</VirtualHost>
At the moment, all traffic to both skylarkapp.com and eamann.com on this system direct to the content of /var/www/html/skylarkapp.com.
Also, I'm using my Windows hosts file to manually point eamann.com to this server (204.92.23.6) because I'm in the process of migrating a live site. I want to get things working on the server before I actually move things from one box to another.
Name-based virtual hosts must be turned on explicitly with NameVirtualHost *:80. See http://httpd.apache.org/docs/2.2/vhosts/name-based.html
This line:
<VirtualHost eamann.com:80>
won't work since eamann.com won't resolve to your CentOS server's IP address (only your Windows machine resolves eamann.com to 204.92.23.6). Try making apache listed on any IP by replacing with:
<VirtualHost *:80>
You probably also want:
ServerAlias www.eamann.com
to allow visitors to www.eamann.com to see the site as well. Restart apache after making these changes:
service httpd restart
I have development server setup running Adobe Coldfusion8 (.war install) on top of Caucho Resin v3.1.9. (CentOS 5.3-64bit)
note: This is my first experience with Resin. I am trying to run Coldfusion8 on top of Resin as I was suggested that this would give me great performance gains.
My question is: how I can easily integrate multiple apache virtualhosts like my existing configuration.
On my production server, running CF8, standalone install on Adobe supplied JRun via mod_jrun22.so in apache, I have virtual hosts setup for each of my websites pointing to '/var/www/*/html/, similar to the following (simplified):
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/www.mydomain.com/html
ServerName www.mydomain.com
ServerAlias mydomain.com
</VirtualHost>
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/www.myotherdomain.com/html
ServerName www.myotherdomain.com
ServerAlias myotherdomain.com
</VirtualHost>
This configuration allows me to setup virtual hosts through apache pointing to '/var/www/*/html' so I can quickly deploy websites with Coldfusion Apps.
Well with Resin, it appears I have to also setup <host> tags for each one of my virtual hosts in '/opt/resin/conf/resin.conf'. Thus, having to completely duplicate apache virtual hosts.
What I really want is to be able to setup my apache virtual hosts and then have resin compensate accordingly.
I need a better solution and am completely open to entertaining any suggestion.
In the resin docs it shows an example using regex to change the root directory. Could you create a similar regex that just caught any .com site and set the document root?
From playing with resin/railo and caucho I couldn't find a way at all to just have the virtualhost configuration in apache only. You have to duplicate it to some level anyway. Either by a regex entry or as I did (only had about 10 domains) create a entry for each site.