Apache VirtualHost - domain name - apache

I bought a domain name, one with ".fr" and the other one with ".com"
Now I want to redirect my domaine name to a server running on the port 4000.
For that I used virualhost:
<VirtualHost *:80>
ServerName http://www.example.fr
ServerAlias example.fr
ProxyRequests Off
ProxyVia On
ProxyPass / http://localhost:4000/
ProxyPassReverse / http://localhost:4000/
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>
It works fine when I access ".com" but doesn't work with the ".fr".
Any idea ? thx

Change ServerName and ServerAlias to:
ServerName example.fr
ServerAlias www.example.fr example.com www.example.com

Related

httpd VirtualHost overwrite another VirtualHost

I have a problem whereby my VirtualHost is overriding another VirtualHost on the same domain.
httpd.conf
IncludeOptional conf.d/*.conf
example.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/example/
ServerName www.example.com
ServerAlias www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/html/example/
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/example/example.crt
SSLCertificateKeyFile /etc/httpd/ssl/example/example.key
SSLCertificateChainFile /etc/httpd/ssl/example/chain.cer
ServerName www.example.com
ServerAlias www.example.com
</VirtualHost>
get.example.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/get.example/
ServerName get.example.com
ServerAlias get.example.com
</VirtualHost>
When I created get.example.conf and when I accessed example.com, it is showing the content of get.example.com
Does anyone knows what is going wrong with my configuration?
Found out that I need to include the non-www for the VirtualHost as well. It works if I entered www.example.com but not example.com.
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>
You just have to set up de ServerAlias.
In your example, it should be enough to do as follow:
<VirtualHost *:80>
DocumentRoot /var/www/html/example/
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
Note that ServerName doesn't has www., so that it's gonna match http://example.com, while with the ServerAlias it's gonna match http://www.example.com
Try to change the order of ServerName and ServerAlias to your get.example.conf:
<VirtualHost *:80>
ServerName get.example.com
ServerAlias get.example.com
DocumentRoot /var/www/html/get.example/
</VirtualHost>

Apache proxy forward wildcard subdomain to tomcat

How do I setup the virtual host to forward the subdomin part to my tomcat.
I know * does not work....but how do I achieve something as below.
<VirtualHost *:80>
ProxyPreserveHost On
ServerName *.example.com
ProxyPass /app1 *.localhost:8080/app1
</VirtualHost>
Well that was a stupid question, the
ProxyPreserveHost On
by itself will preserve the original request so I don't have to forward the subdomain.
just the below will work..
<VirtualHost *:80>
ProxyPreserveHost On
ServerName *.example.com
ProxyPass /app1 http://localhost:8080/app1
</VirtualHost>
and my code actually sees http://subdomain.example.com/app1
Use one specific servername (perhaps "dummy"), then use the wildcard in a
ServerAlias statement:
<VirtualHost *:80>
ProxyPreserveHost On
ServerName dummy.example.com
ServerAlias *.example.com
ProxyPass /app1 *.localhost:8080/app1
</VirtualHost>

What's wrong with this simple SSL Vhost declaration?

Any reason why the middle vhost setting is causing an issue w/ Apache? Maybe it's because I don't have the SSL details in there?
<VirtualHost *:80>
ServerName www.windfarmstudios.com
ServerAlias windfarmstudios.com
Redirect permanent / https://windfarmstudios.com
</VirtualHost>
#<VirtualHost *:443>
# ServerName www.windfarmstudios.com
# Redirect permanent / https://windfarmstudios.com
#</VirtualHost>
<VirtualHost *:443>
ServerName windfarmstudios.com
DocumentRoot /var/www/windfarmstudios.com/public_html
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/windfarm.crt
SSLCertificateKeyFile /etc/apache2/ssl/windfarm.key
SSLCACertificateFile /etc/apache2/ssl/windfarm.ca-bundle
</VirtualHost>

Apache web server, multiple applications in different ports with on same server

I have two applications running on Jboss 6 with different context on same port (8180). I have Apache running on the machine port 80. I need to direct the request to appropriate context based on the application being accessed.
I have a dns entry - testServ14, which points to the server IP.
To be more clear, the applications should be accessible via urls something like
http://testServ14/appAcontext/
http://testServ14/appBcontext/
In httpd-vhosts file what should i be using virtualhost or namevirtualhost directives?
How can I achieve this..
Tried the following but did not work...
<VirtualHost *:80>
ServerName http://testServ14/appA
ProxyRequests Off
ProxyVia On
ProxyPass / http://localhost:8180/appA
ProxyPassReverse / http://localhost:8180/appA
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>
<VirtualHost *:80>
ServerName http://testServ14/appB
ProxyRequests Off
ProxyVia On
ProxyPass / http://localhost:8180/appB
ProxyPassReverse / http://localhost:8180/appB
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>
Thanks
-- updated
The following works nicely...you can add other apps with a different context,running on the same port.
<VirtualHost *:80>
ServerName http://us14testServ/
ServerAlias us14testServ
ProxyRequests Off
ProxyVia On
#app1
ProxyPass /app1/ http://localhost:8180/app1/
ProxyPassReverse /app1/ http://localhost:8180/app1/
#app2
ProxyPass /app2/ http://localhost:8180/app2/
ProxyPassReverse /app2/ http://localhost:8180/app2/
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>
If you want to redirect from one url to another, then what you need to use is mod_rewrite.

Apache 2 VHost - www.domain.com works but domain.com goes to registrar

I am using the following VHOST:
<VirtualHost *:80>
#Basic setup
ServerAdmin administrator#mydomain.com
ServerName www.mydomain.com
ServerAlias mydomain.com
<Directory /home/mydomain/public_html/mydomain.com/mydomain/apache/>
Order deny,allow
Allow from all
</Directory>
LogLevel warn
ErrorLog /home/mydomain/public_html/mydomain.com/logs/apache_error.log
CustomLog /home/mydomain/public_html/mydomain.com/logs/apache_access.log combined
WSGIDaemonProcess mydomain.com user=www-data group=www-data threads=20 processes=2
WSGIProcessGroup mydomain.com
WSGIScriptAlias / /home/mydomain/public_html/mydomain.com/mydomain/apache/mydomain.wsgi
</VirtualHost>
It's working fine when I visit www.mydomain.com, but mydomain.com is taking me to my domain registrars holding page (I am using their nameservers for simplicity.) Is this a problem with my vhost file or something I need to configure with the registrar?
Add mydomain.com A record in DNS
Add www.mydomain.com as cname in DNS
In vhost configuration change the entry like this:
ServerName mydomain.com
ServerAlias www.mydomain.com
It will work.