Connecting Apache to Tomcat with AJP - apache

I am trying to launch a localhost application on Ubuntu with Apache and proxy it to Tomcat so that I can use .jsp pages in my application. It seems that this is possible and I think that I am pretty close, but I can't seem to get it quite right. Any help is greatly appreciated! I've never used apache or tomcat before, so please don't hate me if any of this seems stupid.
I've got Apache hosting a site at localhost with this code for the host:
<VirtualHost *:80>
ServerName localhost
ServerAlias test.com
DocumentRoot /var/www/test.com/helloworld
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
This allows me to successfully navigate to my page hello.html by typing localhost/hello.html in the URL. I have read that from this point, I need to insert some code such as:
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /(appname) ajp://localhost:8009/(appname)
ProxyPassReverse /(appname) ajp://localhost:8009/(appname)
and then Tomcat should get the requests. In this case, what would the appname be? My page is located at /var/www/test.com/helloworld/hello.html, so I thought it would be "helloworld", but that does not work. When I leave the appname blank, I see the Tomcat "Congratulations, you've successfully installed Tomcat." when I navigate to localhost, but cannot find my page.
Please help. This is slowly becoming a nightmare. Thanks!

I figured it out. This is super dumb, but I was trying to load the application from /var/www rather than housing it within the tomcat directories. /facepalm
The proxy code I posted in the original question is the only code needed in the virtualhost. Thanks everyone.

Related

Apache The Requested URL has not been found on this server

So, I'm trying to get Codiad on my VPS so that me and a friend can work on a project together, and when I try to index localhost/codiad it gives me this error:
The requested URL /codiad was not found on this server.
however, indexing localhost works perfectly fine, it leads me to the normal apache screen. Here are the contents of my default.conf file, if that helps at all:
<VirtualHost *:80>
ServerName www.dsept.cf
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /codiad /home/Tide/Codiad
<Directory "/home/Tide/Codiad">
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
I'm also following this guide if that helps too: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-codiad-a-web-based-ide-on-an-ubuntu-vps, the directory of default.conf is /etc/apache2/sites-available/default.conf
1) are you sure there should be:
localhost/codiad
or :
localhost/Codiad
2) have you ever changed that .conf? If so, you may have to edit that .conf and add codiad alias/path correctly. Is everything accurate there?

Moodle apache proxy

I'm having troubles setting up a moodle instance behind an apache proxy.
Here's my apache front-end that proxies to the running server.
NameVirtualHost www.example.com:443
<VirtualHost www.example.com:443>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.example.com
ServerAlias www.example.com
ProxyPass / http://192.168.1.101/
ProxyPassReverse / http://192.168.1.101/
SSLEngine on
SSLCertificateFile /etc/ssl/crt/example.com.crt
SSLCertificateKeyFile /etc/ssl/crt/example.com.key
SSLCACertificatePath /etc/ssl/crt
SSLCertificateChainFile /etc/ssl/crt/example.com.bundle.crt
</VirtualHost>
On the concrete server I've got.
$CFG->wwwroot = 'http://192.168.1.101/classes';
And
<VirtualHost 192.168.1.101:80>
ServerAlias 192.168.1.101
ServerAdmin webmaster#localhost
ServerName 192.168.1.101
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
The thing is that I keep getting that moodle is only accessible from 182.168.1.101 something is not quite matching the expected. I've been able to configure confluence and other platforms but moodle doesn't work.
The concrete error is as follows.
Incorrect access detected, this server may be accessed only through "http://192.168.1.101/classes" address, sorry. Please notify server administrator.
Does anyone know what might be happening?
Its a Moodle error message, the wwwroot in config.php has to match.
You could try
$CFG->wwwroot = 'http://' . $_SERVER['HTTP_HOST'];
Although this might not allow some command line updates in Moodle.
On the proxy server, modify the VirtualHost entry as follows:
ProxyPass / http://192.168.1.101/classes
ProxyPassReverse / http://192.168.1.101/classes
For Moodle, what you set in Moodle's config.php for
$CFG->wwwroot
...has to match your ProxyPass and ProxyPassReverse values in the VirtualHost definition on the Proxy server.
So, what's the URL that points to your front end?
That's what you need to set $CFG->wwwroot to.

Apache : client denied by server configuration for some local ressources

i have some troubles to install local website for development.
I have an "client denied by server configuration"' error for some local ressources like .png or .js
My website have following treepath :
website/files
website/app/local
website/app/share
My mainpage is in app/local and can access to files /files but i have 403 error for files in app/share.
I put "chmod -R 777 www-data" on full website directory so what's wrong ?
[SOLVING]I have another little problem : i can't access to my website with localhost/website but only with localhost/
I have reading some tutos and think my following configuration is right (my apache is 2.2) :
<VirtualHost *:80>
ServerName julien.quai13.com
DocumentRoot /home/julien-quai13/www
<Directory />
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin julien#andcotransport.com
ServerName julien.quai13.com/andcotransport
DocumentRoot /home/julien-quai13/www/andcotransport
#<Directory />
# Options FollowSymLinks
# AllowOverride All
#</Directory>
<Directory /home/julien-quai13/www/andcotransport>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And this my /etc/hosts :
127.0.0.1 localhost
127.0.0.1 julien.quai13.com
127.0.1.1 julien-quai13
192.126.0.34 julien.quai13.com
Not very important but annoying, i always have problems when i switch of Wamp to Linux.
Thanks for helping (promise i stay on Linux this time ;)
Well, when using vhosts, if apache doesn't match the URL with any server name, it will serve the first one it comes to, if this is the first one, then localhost will map straight to /home/julien-quai13/www/andcotransport
You should set up a virtualhost for default with DocumentRoot /home/julien-quai13/www and add a Directory directive for this directory, then localhost/andcotransport will work.
Not sure if this is what you meant to write: chmod -R 777 www-data but this is wrong, commands should be chmod -R 755 /home/julien-quai13/www/andcotransport and chown -R julien-quai13:www-data /home/julien-quai13/www/andcotransport
But permissions wouldn't give you a client denied by server configuration error, this is down to allow being set incorrectly.
Also you have defined julien.quai13.com twice in your hosts file.. one points to 127.0.0.1 and another points to 192.126.0.34.. this may be another problem..
Otherwise i'd consider restructuring your vhosts.
Judging by your vhost:
<VirtualHost *:80>
ServerName julien.quai13.com
DocumentRoot /home/julien-quai13/www
<Directory /home/julien-quai13/www>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
You don't actually need the second vhost unless its under a different domaing, like andcotransport.julien.quai13.com so, just use the default domain and pass everything to /andcotransport, if thats how you want to do it...
but make sure all your resources are going to /andcotransport/files and /andcotransport/app/share then this should work, unless you have an overriding ACL somewhere which is blocking directories.

Apache Reverse Proxy not rewriting URLs the way I expect

I am pretty new to Apache and was hoping to setup a reverse proxy to be able to access so the web interfaces of some IP Cameras I have from one site. The basic layout I'm using is below:
/ Cam 1 - 192.168.1.10
Reverse Proxy - 192.168.1.6 -
\ Cam 2 - 192.168.1.11
When I click a link it doesn't resolve correctly, the URL should be http://192.168.1.6/cam1/settings.htm but it resolves to http://192.168.1.6/setting.htm
Not Found
The requested URL /setting.htm was not found on this server.
Apache/2.2.22 (Debian) Server at 192.168.1.6 Port 80
My Config is here, I'm using the standard httpd.conf with the proxy and rewrite modules enabled:
ProxyRequests off
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
<VirtualHost *>
Servername webserver
RewriteEngine on
RewriteRule ^/cam1/(.*)$ http://192.168.1.10$1 [P]
RewriteRule ^/cam2/(.*)$ http://192.168.1.11$1 [P]
ProxyPass /cam1 http://192.168.1.10
ProxyPassReverse /cam1 http://192.168.1.10
ProxyPass /cam2 http://192.168.1.11
ProxyPassReverse /cam2 http://192.168.1.11
</VirtualHost>
Any help would be appreciated.
Cheers,
Adam
In logs you can clearly see that there are some files missing like File does not exist: /var/www/jpg and /var/www/lang so may be this is the reason for your storage issue.I bet you that you missed some configuration while server OR your server msy corrupt these files while running due to some other files.I suggest you to fresh download and then reinstall it.
For future users:
cat /etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin user#work.com.br
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from 192.168.5.25
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass /cameras/ http://192.168.5.6/
ProxyPassReverse /cameras/ http://192.168.5.6/

More than one virtual host in Apache2 Ubuntu

I have tried to configure a new virtual host in apache. I have copied the default. Updated the paths. The conf looks like this
<VirtualHost *:8081>
ServerAdmin webmaster#localhost
DocumentRoot /home/ubuntu/video
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/ubuntu/video>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/ubuntu/video/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /home/ubuntu/video/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I ran the command
sudo a2ensite video
which gave messaage that virtual host successfully added and will run upon reload. But i am not able to access the same. I have checked the path /home/ubuntu/video where error.log, access.log files are also created. I am not able to find the solution as well as problem. I searched in the internet if anyone have same problem.
The following blog post: Adding virtual hosts to Ubuntu Apache, says in its update the we cannot create more than one virtual host. I have already a virtual host installed. Does this mean 2nd virtual host cannot be configured in Ubuntu for apache?
Read these instructions.
If you try using <VirtualHost name:port> without the NameVirtualHost name:port or you try to use the Listen directive, your configuration will not work.
So make sure you have these directives outside the <VirtualHost> tag:
Listen 8081
NameVirtualHost *:8081
You can also add:
ServerName www.example.com
to your VirtualHost section.