Issue in apache virtualhost - apache

I have an elastic load balancer which direct all the requests at port 80 to my ec2 instance where i have apache installed and i have defined the main server configuration and a virtual host.
But all request are served by the main server defined in apache httpd.conf file.
my apache configuration is having following details:
DocumentRoot "/var/www/html" - for main server
And for sub domain requests:
<VirtualHost p2.neptunetimesheets.com:80>
ServerAdmin webexpertsujeet#gmail.com
DocumentRoot "/var/www/neptunev2"
ServerName p2.neptunetimesheets.com
#ServerAlias p1.neptunetimesheets.com
<Directory "/var/www/neptunev2">
Require all granted
AllowOverride All
Order allow,deny
Allow from all
</Directory>
RewriteEngine On
</VirtualHost>
Is it due to the load balancer that is causing this issue ?

Related

Redirect http default port to an application on same port - CentOS 7

I have an installation of httpd on my server and a web application on it (/var/www/html/app). I want to when a user enter the IP of my server over HTTP (123.125.21.45:80) this redirects to my application on same port (123.125.21.45:80/app)
I have created and app.conf in /etc/httpd/conf.d/app.conf
<VirtualHost *:80>
DocumentRoot /www/html/app
ServerName 123.125.21.45
</VirtualHost>
And the result on the web browser is
http://123.125.21.45/app/app/app/app/app/app/app/app/app/app/app/app/app/app/app/app/app/app/app/app/
What am I doing wrong?
Please use below virtual host file and then try.
Note: make sure you are not using any redirection from .htaccess file.
<VirtualHost *:80>
DocumentRoot /var/www/html/
ServerName 123.125.21.45
Redirect permanent / http://123.125.21.45/app/
<Directory /var/www/html/>
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>

Serving multiple root directories in Apache

I would like my two sites: flowers.loc (Drupal 8) and honey.loc (Drupal 7) sites to work locally on Apache (v: 2.234).
First directory for flowers.loc:
Sites/drupal8/docroot
Second directory for honey.loc:
Sites/drupal7/docroot
I have this setting in httpd, apache configuration file:
<VirtualHost *:80>
DirectoryIndex index.html index.php
DocumentRoot /User/Vizzaro/Sites
<Directory "/User/Vizzaro/Sites">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Have a look at https://httpd.apache.org/docs/2.2/vhosts/examples.html to find out how to set up virtual hosts. Your configuration file has only one virtual host entry but you need one entry for each site. And furthermore your config is missing the ServerName. Try this: (untested)
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName flowers.loc
DocumentRoot /User/Vizzaro/Sites/drupal8/docroot
# Other directives here
</VirtualHost>
<VirtualHost *:80>
ServerName honey.loc
DocumentRoot /User/Vizzaro/Sites/drupal7/docroot
# Other directives here
</VirtualHost>
And be sure that honey.loc and flowers.loc both point to the IP of the machine on wich your apache is running. Try ping flowers.loc - if this results in an error like Name or service not known you probably have to edit your hosts file to fix it.

Proxying between tomcat and apache

I have apache2 and tomcat7 in /var/lib/tomcat7. I have my two apps in tomcat webapps: app1 and app2. I have configured my apache virtual host as below:
#
<VirtualHost *:80>
ServerName myweb1.com
ProxyRequests Off
ProxyPass / http://localhost:8080/web1/
ProxyPassReverse / http://localhost:8080/web1/
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
#
myweb1.com is running in a browser but when I make another vhost for web2, myweb2.com is not loading. Yet when I do myweb2:8080/web2 in my browser it's loading the page. What could be the reason for this? Note that myweb2.com has no problem with DNS entry.
I have tried to put web2 into /opt/tomcat9/webapps but the same results come.

Wampserver shows 404 errors after swapping to using Vhosts

So I was using Wampserver for developing purposes, and I managed to set up the server for developing purposes (it worked with Dreamweaver, PHP worked etc.) but when accessing localhost, I get a 404 error.
I've hardly changed the settings, other than setting it to use that vhosts file, then I made a few new hosts in the hosts file in system 32, which all works fine.
localhost/phpmyadmin does work, however, so I am really stumped as to why it won't load anything. I also tried loading one of the site folders (localhost/Rufus) which also returned a 404. I have all the directories I need pointing to www folder, where all my files are saved.
And before anyone says, no it's not Skype or IIS, as they are both off and Wampserver is running on port 80 (I checked)
My vhosts file:
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<Directory C:\Users\Tom\sites\wamp\www>
Order Deny,Allow
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www\Rufus"
ServerName rufus.stone
</VirtualHost>
Remove the sample virtual hosts, assuming you aren't using them. You also need a virtual host for 'localhost' and it must be the first virtual host. After that you can include your other, custom vhosts.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www\Rufus"
ServerName rufus.stone
</VirtualHost>
If you get a permission denied error try putting the directive I took out into your httpd.conf:
<Directory "C:\Users\Tom\sites\wamp\www">
Order Deny,Allow
Allow from all
</Directory>
It would go right under a similar directive that includes a Deny from all on the root.
Make sure you always restart Apache whenever you make changes to these files.
The error 404 is saying that you have not granted access to those Virtual Hosts, so Apache is kicking you out.
You need to include with your Virtual Host some information to tell Apache which locations are allowed access to each VHOST
You also need to make localhost a Virtual Host and because the first VHOST is the default VHOST it should really be the first you define, and it should always be limited to allow access only from the local machine.
So see if this works any better.
# Virtual Hosts
#
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www"
ServerName localhost
<Directory "C:\Users\Tom\sites\wamp\www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\Tom\sites\wamp\www\Rufus"
ServerName rufus.stone
<Directory "C:\Users\Tom\sites\wamp\www\Rufus>
AllowOverride All
Require local
</Directory>
</VirtualHost>
Require local says allow access from the PC running WAMPServer only.
If later you want to allow other PC's on your internal network to see the Apache server you can add to that like this, for example.
Require local
Require ip 192.168.1
This, assuming you are on the subnet 192.168.1.? will allow any PC connected to your router (wired or wifi) access to the server.
You should avoid these, unless you actually want the world to access your site
Require all granted
OR the Apache 2.2 syntax, which still works on Apache 2.4
Order Deny,Allow
Allow from all

Apache Default Proxy

I have an internal web server (192.168.1.2) that manage multiple domains.
Now i need to put in DMZ one more server, acting as reverse proxy (it's an Apache 2.2.3, with IP 192.168.1.3 and one more interface with static internet IP)
I need this Apache server should proxy any domain coming from internet to my internal web server except for one domain (this.example.com)
A sort of schema:
INTERNET->Apache Proxy->Internal Web server (default for any domain)
INTERNET->Apache Proxy->Differente Web Server (this.example.com)
What kind of configuration do i have to setup on this Apache Proxy? I read about Proxypass and similar string, but i didn't understand how to proxy "the default" to my internal web server...
Thank you for your help
This is working on "defaults", but domain this.example.com does not work...
NameVirtualHost *:80
<VirtualHost *:80>
RewriteEngine On
RewriteRule ^(.*)$ http://192.168.1.2$1 [P]
</VirtualHost>
<VirtualHost *:80>
LogLevel warn
ServerName this.example.com
DocumentRoot /var/www/html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
#AllowOverride None
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>