apache virtual host redirect traffic works in LAN but not WAN - apache

I have a domain hosted by yahoo.
But i am using my own in house server to actually host my Domain and cloud sub domain.
so in the Yahoo, i forward all www.mydomain.com to my static ip
<meta http-equiv="refresh" content="0; url=http://111.111.111.111">
and all my sub-domain traffic to my static ip:
<meta http-equiv="refresh" content="0;URL=http://111.111.111.111/cloud" />
My in-house server is Apache 2.4.7 on Ubuntu 14.04LTS. I have created a virtual host site and enabled it and it works very well as long as i am in the LAN. When i am on the WAN, however, the web browser times out saying that the server stopped working.
I think i know where the problem is, but i am not sure how to solve it, namely in the redirect to the htpps - i am using a LAN IP. Using my static IP or my domain name did not help me solve this. here is my enabled site for my virtual host:
<VirtualHost *:80>
ServerAdmin admin#myexample.com
ServerName www.myexample.com
ServerAlias myexample.com
DocumentRoot /var/www/html/example-test/
Alias / /var/www/html/example-test/
### Redirect /cloud https://www.myexample.com/cloud
Redirect /cloud https://192.168.1.122/cloud
### Redirect /cloud https://111.111.111.111/cloud
<Directory /var/www/html/example-test>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
<Directory /var/www/owncloud>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache_http_myexample.com.error.log
</VirtualHost>
### <VirtualHost www.myexample.com:443>
<VirtualHost 192.168.1.122:443>
### <VirtualHost 111.111.111.111:443>
ServerAdmin admin#myexample.com
ServerName www.myexample.com
ServerAlias myexample.com
Alias /cloud /var/www/owncloud
DocumentRoot /var/www/owncloud/
####Configuration for SSL #####
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/examplecloud.pem
SSLCertificateKeyFile /etc/apache2/ssl/examplecloud.key
#### End of SSL Configuration ####
<Directory /var/www/owncloud>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache_https_cloud.myexample.com.error.log
</VirtualHost>
~
Any help/insight would be much appreciated...
thanks,

Try Redirect permanent /cloud https://192.168.1.122/cloud
If that didn't work, try a more generic solution by replacing Redirect with:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}

Related

Apache virtual host subdomains not working

I am using httpd-vhosts.conf,apache version 2.4.51 and Windows Server.
The subdomain is not working.
httpd-vhosts.conf:
NameVirtualHost *:80
#
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "e:/wamp64/www/mydomain.com"
<Directory "e:/wamp64/www/mydomain.com/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
#
<VirtualHost *:80>
ServerName subdomain.mydomain.com
ServerAlias subdomain.mydomain.com
DocumentRoot "e:/wamp64/www/mydomain.com/subdomain"
<Directory "e:/wamp64/www/mydomain.com/subdomain/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Both mydomain.com and www.mydomain.com works great!
But if i try using: http://subdomain.mydomain.com i always got the error:
Hmm. We’re having trouble finding that site.
We can’t connect to the server at subdomain.mydomain.com
If that address is correct, here are three other things you can try:
Try again later.
Check your network connection.
If you are connected but behind a firewall, check that Firefox has permission to access the Web.
hosts file is correct too:
127.0.0.1 mydomain.com
::1 mydomain.com
127.0.0.1 subdomain.mydomain.com
::1 subdomain.mydomain.com
P.S. I can access it directly from the host machine, but i can't on another device.
Why only the subdomain is not working, please?
What am i missing?
Thank you!!!
It seems to be more a DNS problem than a config problem on your serveur. Did you set any DNS for your subdomain ? Maybe you could find some help here :
https://www.godaddy.com/help/create-a-subdomain-4080

Apache Reverse Proxy For Specific Subdomain

I'm have a an Apache HTTP server that has a reverse proxy to a tomcat server. However, I only want the reverse proxy to happen when the client uses the subdomain www. This is because I want to use other subdomains to point to other applications, such as email.
e.g. www.example.com will go display the apache tomcat webapp.
The way to do this, I presume, is to configure my DNS so that every subdomain I use will point to my server. Right now, in addition to www, that is server.example.com and posfixadmin.example.com. However, the issue is that all my subdomains end up pointing to tomcat.
So when I try to visit postfixadmin.example.com/setup.php to set up postfixadmin through its web setup, it ends up taking me to my tomcat webapp's 404.
Here is my virtualhost configuration:
<VirtualHost www.example.com:80>
ServerName http://www.example.com
ProxyPass / http://localhost:8080
ProxyPassReverse / http://localhost:8080
</Virtualhost>
<VirtualHost server.example.com:80>
ServerName server.example.com
DocumentRoot /var/www/html/
RewriteEngine on
RewriteCond %{SERVER_NAME} =server.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} {END,NE,R=permanent}
</VirtualHost>
<VirtualHost postfixadmin.example.com:80>
ServerName postfixadmin.example.com
DocumentRoot /var/www/postfixadmin/public
ErrorLog /var/log/httpd/postfixadmin_error.log
CustomLog /var/log/httpd/postfixadmin_access.log combined
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/postfixadmin/public>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
EDIT
It looks like the proxy conf file doesn't do anything (??). I decided to experiment around and change the first virtualhost servername to the following:
<VirtualHost *:80>
ServerName abcd.example.com
ProxyPass / http://localhost:8080
ProxyPassReverse / http://localhost:8080
</Virtualhost>
Then, I restarted and reloaded Apache...But for some reason, going to www.example.com STILL took me to the tomcat webapp! Does anyone know what drives this?
As to the DNS: I have set specific CNAME entries for each subdomain including www; all of them point back to the public IP of my server that houses my example.com domain (using # in my case - possible with most DNS, I think). There may be some different strategies on this, but I believe you're on the correct path based on what you've suggested in the question.
As to Apache configuration:
I believe that the http protocol does not need to be specified in the ServerName directive and that, generally, the domain need not appear inside the <VirtualHost>...</VirtualHost> tags.
I should mention that I am relatively unfamiliar with Tomcat but am assuming it is listening at 8080 on the localhost, in which case this should help.
I'm not 100% certain that that is all that is snarling you, but try trimming that ServerName back and doing like so, including the change to the VirtualHost open tag:
<VirtualHost *:80>
ServerName www.example.com
ProxyPass / http://localhost:8080
ProxyPassReverse / http://localhost:8080
</Virtualhost>
Your second <VirtualHost> probably requires similar changes, though it also seems that you are directing it to serve requests from the web/network which are coming in on port 8080 -- which I don't believe is your intent.
I think what you want is to also listen on port 80 from the web/network, but to follow these directives if addressed to server.example.com like so:
<VirtualHost *:80>
ServerName server.example.com
DocumentRoot /var/www/html/
RewriteEngine on
RewriteCond %{SERVER_NAME} =server.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} {END,NE,R=permanent}
</VirtualHost>
And finally, similar change to the opening <VirtualHost> tag on the final one:
<VirtualHost *:80>
ServerName postfixadmin.example.com
DocumentRoot /var/www/postfixadmin/public
ErrorLog /var/log/httpd/postfixadmin_error.log
CustomLog /var/log/httpd/postfixadmin_access.log combined
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/postfixadmin/public>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Altogether, this seems more like what you're looking for:
<VirtualHost *:80>
ServerName www.example.com
ProxyPass / http://localhost:8080
ProxyPassReverse / http://localhost:8080
</Virtualhost>
<VirtualHost *:80>
ServerName server.example.com
DocumentRoot /var/www/html/
RewriteEngine on
RewriteCond %{SERVER_NAME} =server.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} {END,NE,R=permanent}
</VirtualHost>
<VirtualHost *:80>
ServerName postfixadmin.example.com
DocumentRoot /var/www/postfixadmin/public
ErrorLog /var/log/httpd/postfixadmin_error.log
CustomLog /var/log/httpd/postfixadmin_access.log combined
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/postfixadmin/public>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I got it!
It turns out that the problem was in the ssl configuration file - the :443 ports were overlapping.
Thanks for the help!

WAMP Server will not allow access to website using "www"

I cannot access my website using "www" before domain name but I can if I don't use the "www". I would like to have both accessible.
I am very familiar using Apache2 Server on Linux but it's not often I have to use it alongside WAMP. I have done plenty of messing around in the config files and have tried a few different methods but nothing seems to be working.
Here is the httpd-vhosts.conf file:
# Virtual Hosts
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName wherehousemke.com
DocumentRoot "c:/wamp64/www/wherehousemke"
<Directory "c:/wamp64/www/wherehousemke/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
Require all granted
</Directory>
</VirtualHost>
The website that I am trying to get this to work for is http://wherehousemke.com. That URL is working but if you add "www" in there It will NOT work.
you need to add a DNS record that redirects from your TLD to the www subdomain https://www.digitalocean.com/community/questions/using-cname-for-www-redirection

Subdomain on WAMP Server Not Working

I'm having an important issue with my WAMP Server configuration. I've tried many configurations listed on many websites to no avail. I'm trying to make the directory /forums be accessible via https://forums.centmc.tk. However, upon travelling to https://forums.centmc.tk, it almost immediately says "forums.centmc.tk's server IP address could not be found." https://centmc.tk works fine, and so does the 301 redirect from https://centmc.tk/forums to https://forums.centmc.tk. I just can't figure out why the subdomain won't work.
I know it's an issue with my httpd-vhosts.conf file, so here's that:
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "c:/wamp64/www"
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot c:/wamp64/www
ServerName centmc.tk
SSLEngine on
SSLCertificateFile c:/wamp64/bin/apache/apache2.4.27/conf/centmc.tk.crt
SSLCertificateKeyFile c:/wamp64/bin/apache/apache2.4.27/conf/centmc.tk.key
Redirect 301 /forums https://forums.centmc.tk
Redirect 301 /forum https://forums.centmc.tk
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName centmc.tk
ServerAlias forums.centmc.tk
VirtualDocumentRoot "c:/wamp/www/forums"
ErrorLog "c:/wamp64/bin/apache/apache2.4.27/logs/errors.log"
<Directory "c:/wamp/www/forums">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Thanks for any help in advance! Sorry for the rather large text brick at the top.
Lucas.
Sounds like a DNS problem. If you are running a DNS server on your network, you will need to add an "A" record for the "forums" subdomain. Something like this:
; example.com [448369]
$TTL 86400
# IN SOA ns1.linode.com. admin.example.com. 2013062147 14400 14400 1209600 86400
# MX 10 mail.example.com.
# A ###.###.###.###
mail A ###.###.###.###
www A <put your server IP here>
forums A <put your forums server IP here>
If you're using public DNS servers (like 8.8.8.8, 4.4.4.4, or just your default ISP's DNS servers... you'll need to add a CNAME record to wherever your domain name is registered. (GoDaddy for example). Here's a link to how to do it on GoDaddy: https://www.godaddy.com/help/add-a-subdomain-that-points-to-an-ip-address-4080
I hope that helps.

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>