Reverse Proxying Tomcat Web Applications Behind Apache - apache

I would like to create a configuration for my virtual host in my Ubuntu 14.04 LTS Profile, so I modified the file /etc/apache2/sites-available/mysite.com.conf as follows:
# domain: mysite.com
# public: /var/www/mysite.com/public_html/
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin webmaster#mysite.com
ServerName www.mysite.com
ServerAlias mysite.com
ProxyPass / http://139.333.222.107:8080/devices
ProxyPassReverse / http://139.333.222.107:8080/devices
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/mysite.com/public_html
# Log file locations
LogLevel warn
ErrorLog /var/www/mysite.com/log/error.log
CustomLog /var/www/mysite.com/log/access.log combined
</VirtualHost>
But when I run sudo service apache2 restart , I got this error:
* Restarting web server apache2 [fail]
* The apache2 configtest failed.
Output of config test was:
AH00526: Syntax error on line 9 of /etc/apache2/sites-enabled/mysite.com.conf:
Invalid command 'ProxyPass', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.

You are not including mod_proxy. Depends on your install (sorry not familiar with Ubuntu) but usually this means the following line will be in your main httpd.conf file:
#LoadModule proxy_module modules/modproxy.so
Remove the # so it stops being commented out and is loaded and restart Apache.
This link may also help: https://askubuntu.com/questions/341684/how-to-load-the-modules-for-apache2

Related

Apache2 keeps redirecting to default page

I've installed some software for users to be able to change their ldap password on they own named self service password on this path: /usr/share/self-service-password/htdocs.
In sites-enabled my configuration is as follows: (file named 000-default.conf)
<VirtualHost *:80>
ServerName <IP>
DocumentRoot /usr/share/self-service-password/htdocs
DirectoryIndex index.php
AddDefaultCharset UTF-8
LogLevel warn
ErrorLog /var/log/apache2/ssp_error.log
CustomLog /var/log/apache2/ssp_access.log combined
</VirtualHost>
(same thing is "configured" at sites-available").
I've made sure this .conf file (000-default) is enabled by a2ensite, and made sure everything else is disabled, and restarted apache2.
However, When browsing to my IP:81 , it keeps redirecting me to Apache default welcome page under /var/www/html .
I'm trying to find a solution for it for the past 2 hours and couldn't find the reason behind it.
Thanks for anyone willing to assist.
As per your configuration your VirtualHost is accepting connections on port *:80
<VirtualHost *:80>
But then you are testing on IP:81.
Could you please adjust your test to IP:80
or
Adjust the VirtualHost port to *:81
They must match to work.

Can't setup SubDomain on Linode Server

I have bought a server from linode.com and set it up with my purchased domain from namecheap. Setting up the DNS worked as expected and I followed the official documentation from linode.
But whenever I am trying to set up a subdomain in the same server, despite following the same documentation, for some reason I can't set it up.
Here is the config:
Server: Apache on Ubuntu 18.04
Domain: randomxyz.xyz
Here are the steps that I followed:
Created AAAA record in Linode Manager Panel.
IP -> Server IP.
Hostname -> temp.
SSH into the server.
created a folder named temp.randomxyz.xyz inside var/www/html.
created public_html, log and backups folders for temp.randomxyz.xyz.
created temp.randomxyz.xyz.conf in etc/apache2/sites-available
put Vhost config in the conf file:
# domain: randomxyz.xyz
# public: /var/www/html/randomxyz.xyz/public_html/
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin ok#randomxyz.xyz
ServerName temp.randomxyz.xyz
ServerAlias temp.randomxyz.xyz
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/html/temp.randomxyz.xyz/public_html
# Log file locations
LogLevel warn
ErrorLog /var/www/html/temp.randomxyz.xyz/log/error.log
CustomLog /var/www/html/temp.randomxyz.xyz/log/access.log combined
</VirtualHost>
Enable the new configured site: a2ensite temp.randomxyz.xyz
Reload Apache: systemctl restart apache2
I have waited for more than 48 hours. The Subdomain is not working.
What am I missing here?
Do I have to do something in namecheap manager?

Apache: Serving content from two different locations and ports

I have an Apache server running on Ubuntu 14 on a server on which I have sudo.
When users request the server's IP, Apache serves content from /var/www/html.
I'd like to keep this behavior intact, and make it so that users who request IP/cats get some special content that's hosted by a Docker container on port 7777.
What's the best way to achieve this functionality in Apache?
With thanks to #arkascha I did the following to get this going:
Create a file /etc/apache2/sites-available/wow.conf with the following content:
<VirtualHost *:*>
# enable proxies
ProxyPreserveHost On
ProxyPass /cats http://0.0.0.0:7777/
ProxyPassReverse /cats http://0.0.0.0:7777/
ServerAdmin douglas.duhaime#yale.edu
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This says when requests come in for IP/cats, serve the users the content from port 7777.
I then symlinked this file to the sites-enabled directory:
sudo ln /etc/apache2/sites-available/wow.conf /etc/apache2/sites-enabled/wow.conf
Finally, I needed to delete the default sites enabled file and restart the server:
sudo rm /etc/apache2/sites-enabled/000-default.conf
sudo service apache2 restart
P.S. Apache is amazing.

Invalid command 'PassengerAppRoot', perhaps misspelled or defined by a module not included in the server configuration

I have followed every step for installation given in Installing Passenger + Apache on a Linux/Unix production server
for Node.js apps + Red Hat 6 / CentOS 6 (with RPM) and everything worked but when I am trying to configure my subdomain in virtualhost on my centos 6 server using WHM to host my botkit bot, I get this error :
The “/usr/local/apache/bin/httpd” command (process 27088) reported
error number 1 when it ended. Configuration problem detected on line 9
of file /usr/local/apache/conf/includes/post_virtualhost_2.conf.tmp:
Invalid command 'PassengerAppRoot', perhaps misspelled or defined by a
module not included in the server configuration ---
/usr/local/apache/conf/includes/post_virtualhost_2.conf.tmp --- 3
ServerAlias subdomain.mydomain.com 4 ServerAdmin
adminserver#mydomain.com 5 6 7 # Tell Apache and Passenger where your
app's code directory is 8 DocumentRoot /var/www/MyApp/Code/public 9
===> PassengerAppRoot /var/www/MyApp/Code <=== 10 #Error logging 11 ErrorLog logs/subdomain-error_log 12 CustomLog
logs/subdomain-access_log common 13 14 # Tell Passenger that your app
is a Node.js app 15 PassengerAppType node ---
/usr/local/apache/conf/includes/post_virtualhost_2.conf.tmp ---
Here is my configuration:
<VirtualHost *:80>
ServerName www.subdomain.mydomain.com
ServerAlias subdomain.mydomain.com
ServerAdmin adminserver#mydomain.com
# Tell Apache and Passenger where your app's code directory is
DocumentRoot /var/www/MyApp/code/public
PassengerAppRoot /var/www/MyApp/code
#Error logging
ErrorLog logs/votebot-error_log
CustomLog logs/votebot-access_log common
# Tell Passenger that your app is a Node.js app
PassengerAppType node
PassengerStartupFile bot.js
# Relax Apache security settings
<Directory /var/www/MyApp/code/public>
Allow from all
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
#Require all granted
</Directory>
</VirtualHost>
I tried to remove the configuration and pass via .htaccess :
PassengerEnabled on
PassengerAppRoot /var/www/MyApp/code
SetEnv NODE_ENV production
SetEnv NODE_PATH /usr/lib/node_modules
PassengerAppType node
PassengerStartupFile bot.js
But still it is not working.
I checked lately and got the following message when validating passenger :
* Checking whether this Passenger install is in PATH... ✓
* Checking whether there are no other Passenger installations... (!)
You are currently validating against Phusion Passenger 5.1.8, located in:
/usr/bin/passenger
Besides this Passenger installation, the following other
Passenger installations have also been detected:
/usr/local/rvm/gems/ruby-2.4.1/bin/passenger
Please uninstall these other Passenger installations to avoid
confusion or conflicts.
The problem is I don't know what are the steps to uninstall /usr/local/rvm/gems/ruby-2.4.1/bin/passenger .
That error means that the Passenger module hasn't been loaded with a LoadModule passenger_module /path/to/.../passenger/buildout/apache2/mod_passenger.so line in your apache config before the Passenger config options are specified.
If sudo /usr/bin/passenger-config validate-install passed the apache config test, then you have multiple apache configs and the wrong one is being loaded when you get the error.
From your error the conf is at /usr/local/apache/conf/, look for any LoadModule lines in the config with fgrep -RH LoadModule /usr/local/apache/conf/ and add a line to load the Passenger module.

Apache Server Unable to host multiple domain on single Public IP Error : "Not Found The requested URL / was not found on this server."

Apache Server Unable to host multiple domain on single Public IP running on Windows Server 2016
Error:"Not Found The requested URL / was not found on this server." 404 Not Found
Progress so far :
1)Edited Windows hosts file "C:\Windows\System32\drivers\etc\hosts": to below
127.0.0.1 localhost
::1 localhost
127.0.0.1 koffeeroasters.com
2)Changes made in the httpd.conf file of apache is below
changed
#Include conf/extra/httpd-vhosts.conf
to
Include conf/extra/httpd-vhosts.conf
also changed
#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so
and added to the end of the file the following
# Tells Apache to identify which site by name
NameVirtualHost *:80
# Tells Apache to serve the default WAMP Server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wampstack/apache2/htdocs"
</VirtualHost>
# Tells Apache to serve Client 1's pages to "client1.localhost"
# Duplicate and modify this block to add another client
<VirtualHost 127.0.0.1>
# The name to respond to
ServerName koffeeroasters.com
ServerAlias www.koffeeroasters.com
# Folder where the files live
DocumentRoot "C:/wampstack/apache2/htdocs/koffeeroasters.com/"
# A few helpful settings...
<Directory "C:/wampstack/apache2/htdocs/koffeeroasters.com/">
Order Allow,Deny
Allow from all
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.html index.php
</VirtualHost>
Other details
I am using apache server on bitnami wampstack.
Site is available when typed the address "koffeeroasters.com" from the servers browser.
A reason for it which I know no solution of (refered from apache docs "https://httpd.apache.org/docs/2.4/vhosts/examples.html") :
Note :
Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries.
Thanks a bunch. All help appreciated.
Try changing this:
<VirtualHost 127.0.0.1>
to
<VirtualHost *:80>
This means allow any other IPs connect on port 80, which should get you going. Trying to match the localhost is doing more than you probably need, unless you are public facing server, in which case you will not want to do this.