Additional virtualhost with Websphere apache plugin - apache

Current I have Apache Httpd and Websphere with Apache config generated with Websphere apache plugin. What I want to do is write virtualhost which overlap some of move with usage of provy pass, for example:
<VirtualHost *:80>
ServerAlias test-*-test
ServerSignature On
ProxyPreserveHost On
ProxyPass /test/ ajp://localhost:1234/test/
</VirtualHost>
Earlier in this conf file I have only WebSpherePluginConfig with path.
New virtualhost is working as it should, but unluckily it overrides somehow all plugin config (even for another server aliases). How to make it to only override this specific path.

The first listed virtual host for *:80 is the default. Add a new first vhost without proxypass, so the vhost in your question will only be used when the hostname actually matches.

Related

Include external file in apache conf

I am running apache 2.4 on my web servers and I am always trying to find ways to streamline. Is it possible to include a conf file for every Joomla website and another one for every Wordpress site that I host? I put the Joomla .htaccess configuration (https://docs.joomla.org/Special:MyLanguage/Preconfigured_htaccess) inside of the domainname.com.conf file and specify Allowaccess none for performance reasons.
It would be great to have a single file for different versions of Joomla, Wordpress or other apps that require Apache configurations instead of needing to edit dozens of conf files when the app requirements change.
I found the include directive from Apache, but not sure if it would work on an individual vhost. http://httpd.apache.org/docs/2.4/mod/core.html#include
The Include does work for individual vhosts.
The documentation you linked (https://httpd.apache.org/docs/2.4/mod/core.html#include) states this in the header block of the section:
Context: server config, virtual host, directory
That means that the "Include" directive can be used, amongst other places, in the virtual host section of the configuration.
See here for a definition of the contexts: https://httpd.apache.org/docs/2.4/mod/directive-dict.html#Context
So you could do this:
<VirtualHost *:80>
ServerName joomla1.example.com
Include "conf/joomla.conf"
</VirtualHost>
<VirtualHost *:80>
ServerName joomla2.example.com
Include "conf/joomla.conf"
</VirtualHost>
<VirtualHost *:80>
ServerName wordpress1.example.com
Include "conf/wp.conf"
</VirtualHost>
<VirtualHost *:80>
ServerName wordpress2.example.com
Include "conf/wp.conf"
</VirtualHost>
joomla.conf and wp.conf would contain the directives that are common to either Joomla or Wordpress.

Apache VirtualHost : multiple sites on same IP

Let assume that blah.com, blah2.com all point to the same server with IP=5.31.111.7.
I would like that:
accessing blah.com serves /var/www/site1
accessing blah2.com serves /var/www/site1
accessing 5.31.111.7 serves /var/www/site2
I tried
<VirtualHost *:80>
DocumentRoot /var/www/site1
</VirtualHost>
<VirtualHost 5.31.111.7:80>
DocumentRoot /var/www/site2
</VirtualHost>
but now everything goes to /var/www/site2, which is not what I wanted.
How to configure the VirtualHost, such that the served website depends on the URL ?
PS: why should I do this in /etc/apache2/sites-enabled/000-default instead of /etc/apache2/apache2.conf ? I don't understand this sites-enabled / sites-available/default naming... Why are there so many different config files by default on Debian, for such a simple thing?
What you want to do is called Name-Based Virtual Hosting, you'll need
NameVirtualHost *:80
to enable it on port 80, and for each VirtualHost, you need to give the name(s):
<VirtualHost *:80>
ServerName blah2.com
ServerAlias www.blah2.com
DocumentRoot /var/www/site1
</VirtualHost>
Note that there are limitations on SSL/TLS when doing name-based virtual hosting, but it's a bit of a moot point since post-POODLE, people start to require TLS anyway, so ancient browsers are out of luck anyway.
As to the config files, it's very very useful to have two classes of config files: the ones with defaults that a package update will overwrite, and your local ones that it will not touch, or better even, a directory full of the former and a directory full of the latter. (Because additional packages might want to make configuration settings, they'll all install in the former place, and you should only ever change/override config in the second place.)

How do you set the default website to serve when your IP address is entered as URL?

I have a server with multiple websites hosted and distinguishable using name-based virtual hosting of apache.
How do I set it so that a specific website is hosted when the ip of my server is entered in the address bar?
What you want to use is the _default_ VirtualHost.
<VirtualHost _default_:80>
DocumentRoot /www/default80
# ...
</VirtualHost>
It's described here. Basically if nothing else match the request the _default_ host will be used.
EDIT
This could also be written as:
<VirtualHost *>
DocumentRoot /www/default
# ...
</VirtualHost>
Is is important that this is the first VirtualHost in the configuration since Apache will start matching them from top to bottom, selecting the one that fit the best based on ServerName and ServerAlias.
This post might also be of interest:
Apache default VirtualHost
just find the Include sites-enabled/ line in your apache2.conf file and add the path to the conf file you want to be site default above it. from:
Include sites-enabled/
to
Include sites-enabled/mydefault.conf
Include sites-enabled/
When you first install apache2, there is a site configuration file named 000-default.conf. This is going to be the default because it is very likely to appear first in the list of files under /etc/apache2/sites-enabled.
To have your own file as the default, you can either replace the file under /etc/apache2/sites-available/000-default.conf with your own, or replace the link like so:
sudo rm /etc/apache2/sites-enabled/000-default.conf
sudo ln -s ../sites-available/my-site-setup.conf /etc/apache2/sites-enabled/000-default.conf
Then restart apache2 (or just reload).
The _default_ as mentioned by the other answer is for defining a virtual host which can be found with the default IP address. It's not the default virtual host.
<VirtualHost _default_:80>
...
is equivalent to
<VirtualHost *:80>
...
The * is a globing pattern which matches any IP addresses.
Note:
Replacing the 000-default.conf file is okay, but in most cases the installation package is going to view that as a modified file and manage it in some weird way which is why I think it's cleaner to only change the soft link.
Keep it clean, don't delete or edit anything in /etc/apache2/sites-available/.
Create all new site configurations in /etc/apache2/sites-available/. Copy whatever site configuration you want enabled to /etc/apache2/sites-enabled/. Only make sure /etc/apache2/sites-enabled/ has only one configuration file.
Sample format for new apache site configurations in Ubuntu 20.04 LTS is
<VirtualHost *:80>
ServerName http://localhost
ServerAdmin admin#mysite.com
DocumentRoot /var/www/html/mysiteroot/public
<Directory /var/www/html/mysiteroot>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Notice that 000-default.conf is by default in both directories mentioned above and should only be replaced by your new configuration in /etc/apache2/sites-enabled/ so that it can be restored anytime you need it.
Restart Apache2 service after you make any configuration changes.

How to create Virtual Host from Apache .htaccess?

I am using Apache Friends XAMPP in Windows (Local Server). I setup the virtual host in httpd-vhosts.conf in an Apache configuration directory like this
NameVirtualHost *:80
<VirtualHost *:80>
ServerName test.example.com
DocumentRoot "E:\xampp\htdocs\example"
</VirtualHost>
This works fine when I browse the URL
http://test.example.com
Is it possible to create virtual host from Apache .htaccess dynamically?
The context for VirtualHost has to be server config. See the Apache docs.
This means that the directive may be
used in the server configuration files
(e.g., httpd.conf), but not within any
or
containers. It is not allowed in
.htaccess files at all.
(Directive Dictionary)
It seems to be impossible. Because your .htaccess is used only after your host is resolved by root configuration files of a server like httpd.conf, apache2.conf.
To put simply, .htaccess in the www directory or in its subdirectories will only be processed after root configuration files are processed.
I mean you type http://host.name and apache finds the destination and uses .htaccess file on the host to perform some operations if needed.

Apache - Tomcat ProxyPass VirtualHost - Context Path

I have a problem configuring apache tomcat ProxyPass directive for two applications that have two different Context Paths in tomcat. The tomcat is running behind an apache and I use the apache to proxy path the requests to tomcat. In apache I want to access both application via a hostname instead of a context path.
Scenario:
tomcat
https://domain:8443/app1
https://domain:8443/app2
in tomcat the applications have the context path app1 and app2
in apache I want to enable both application as follow:
https://app1.host/
https://app2.host/
In apache I have created a configuration for each domain:
ProxyPass / https://localhost:8443/app1
ProxyPassReverse / https://localhost:/8443/app1
The strange thing is app1 is only available through apache using the context path:
https://app1.host/app1
Is it possible to realize such a setup with apache ProxyPass module?
Thx for your help.
You should be able to achieve the result you want by using virtual hosting. Also it's a good idea to pass the requests to tomcat via the AJP protocol instead of HTTPS. Try adding this to the Apache configuration
NameVirtualHost *:443
<VirtualHost *:443>
ServerName app1.host
ProxyPass / ajp://localhost:8009/app1/
</VirtualHost>
<VirtualHost *:443>
ServerName app2.host
ProxyPass / ajp://localhost:8009/app2/
</VirtualHost>
If you haven't changed the default server settings for Tomcat this should work just as it is. Otherwise make sure to specify the AJP port that is configured in Tomcat's conf/server.xml file. There should be a line similar to this:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
Make sure that you have the mod_proxy and mod_proxy_ajp modules loaded in Apache configuration, this may vary depending on your Apache installation. Also remove any previously configured 'ProxyPass / ...' lines as they will interfere with the new configuration. Hope this works for you.
you can try
ProxyPass / https://localhost:8443/app1/
ProxyPassReverse / https://localhost:8443/app1/
with the final /