Apache redirect to perl script - apache

I'm currently using Apache's vhosts configuration to redirect request to the server, e.g.
<VirtualHost IP:80>
ServerName http://domain.info
Redirect / http://otherdomain.com
</VirtualHost>
<VirtualHost IP:80>
ServerName http://subdomain.domain.info
Redirect / http://domain:port
</VirtualHost>
Now I installed AWstats which can be started by using the command
http://localhost/cgi-bin/awstats.pl
I assume that if I add this block to vhosts
<VirtualHost IP:80>
ServerName http://stats.domain.info
Redirect / http://domain.info/cgi-bin/awstats.pl
</VirtualHost>
I can remote-access AWstats using
http://domain.info/cgi-bin/awstats.pl
but all I get is
http://otherdomain.comcgi-bin/awstats.pl
What am I doing wrong?
Greetz
holgrich

The question is still open, but for now I used a workaround:
<VirtualHost IP:80>
ServerName http://domain.info
[Redirect to local html that contains frame forwarding]
</VirtualHost>
<VirtualHost IP:80>
ServerName http://subdomain.domain.info
Redirect / http://domain:port
</VirtualHost>
Now this works
<VirtualHost IP:80>
ServerName http://stats.domain.info
Redirect / http://domain.info/cgi-bin/awstats.pl
</VirtualHost>
So that I can remote-access AWstats using
http://domain.info/cgi-bin/awstats.pl

Related

Ubuntu Apache Redirect All Request to HTTPS except Jenkins

I am creating a configuring a Server using Ubuntu and Apache. Everything works fine except that when I use redirection of HTTP to HTTPS.
How can I write an exception case where every http request is redirected to HTTPS except when its for JENKINS.
JENKINS : http://www.example.com:8080/ <= SHould not be redirected to HTTPS
Normal Request : http://www.example.com/ <= Should be redirected to HTTPS
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>
Your sample configuration looks almost correct. You can create a separate VirtualHost for port 8080.
<Virtualhost *:8080>
ServerName example.com
.
.
ProxyPass / http://jenkins:8080/
.
.
</Virtualhost>
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>

How to resolve Jekyll non www to www on 000-default.conf in apache

Switched from wordpress to Jekyll and trying to resolve nonn www to www. Running on ubuntu 14.04.
When I change /etc/apache2/sites-available/000-default.conf with the following in the vhost it works but I get /html sub folder added to the domain. Have I implemented this correctly if so, how do I get rid of it?
<VirtualHost *:80>
ServerName undesired.example.com
ServerAlias example.com notthis.example.com
DocumentRoot /var/www/html
Redirect / http://www.example.com/
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
</VirtualHost>
Figured it out, was missing DocumentRoot in vhost.
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html
</VirtualHost>

redirecting url from one subfolder to another using conf file / ubuntu

I have web site on domain.com
which is located at /var/www/main
I also have started another web site which I want to be on url domain.com/a/b
But the actual file location is /var/www/main/a/b/c
Problem is that I want the users to use url domain.com/a/b and get files from /var/www/main/a/b/c
So I've found domains conf file at /etc/apache2/sites-available/domain.com.conf
It had only this
<virtualhost *:80>
ServerName domain.com
DocumentRoot /var/www/main
</virtualhost>
Now after reading different topics about it I've tried to add this so now my domain.com.conf file looks like this
<virtualhost *:80>
ServerName domain.com
DocumentRoot /var/www/main
</virtualhost>
<virtualhost *:80>
ServerName domain.com
ServerPath /a/b/
DocumentRoot /var/www/main/a/b/c
RewriteEngine On
RewriteRule ^(/a/b/.*) /var/www/main/a/b/c
# ...
</virtualhost>
But this does not work at all.
What am I doing wrong ?
No need for Rewrite Rules. Just set up an alias in /etc/apache2/sites-available/domain.com.conf :
<virtualhost *:80>
ServerName domain.com
DocumentRoot /var/www/main
Alias /a/b /var/www/main/a/b/c
</virtualhost>
Then restart apache :
$ sudo service apache2 restart

Creating Wildcard Sub Domain Using Apache VirtualHost

I want to have this situation :
if user request using this URL : example.com or www.example.com,
user will see index.php in this directory /home/admin1/public_html/
but when user request using other sub domain (wildcard) for example : freediscount.example.com, user will see index.php in this path : /home/admin1/public_html/userweb/freediscount.example.com
technical support on my hosting suggest me to use this method : http://www.wiredstudios.com/php-programming/setting-up-wildcard-dns-for-subdomains-on-cpanel.html
based on that tutorial, the PHP has a new job... to redirect on specific folder when user request with sub domain. I don't like this method. for me, it would be better if Apache can handle this.
nearly close to what I need is this method : Virtualhost For Wildcard Subdomain and Static Subdomain
but, I have a problem with VirtualHost setting, how to create VirtualHost correctly for that situation?
here's what I've done but didn't work :
## I think this one is for www or without www, automatically generated with WHM
<VirtualHost xx.xx.xx.xx:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/admin1/public_html
</VirtualHost>
## Here's what I'm trying to add
<VirtualHost xx.xx.xx.xx:80>
ServerName example.com
DocumentRoot /home/admin1/public_html/userweb/*
</VirtualHost>
Wildcard sub-domains are definitely possible using Apache virtual hosts.
I had basically the same requirements and managed to get it working with Apache's mod_vhost_alias.so module. Try this in your http-vhosts.conf file:
DocumentRoot "/home/admin1/public_html/userweb/"
<Directory "/home/admin1/public_html/userweb/">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName www.example.com
</VirtualHost>
<VirtualHost *:80>
VirtualDocumentRoot /home/admin1/public_html/userweb/%1.example.com/
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName example.com
</VirtualHost>
Note that I haven't tested this, but it's pretty close to the solution that worked for me.
Full details of my solution are here:
http://www.calcatraz.com/blog/wildcard-subdomains-in-apache-1422
Try with this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName www.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/userweb/freediscount.example.com
ServerName other.example.com
ServerAlias *.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName example.com
</VirtualHost>
Order of virtual hosts & their specificity matters.

Redirect http to https by configuring .conf file of apache

I have configure apache to tomcat configuration by code like
<VirtualHost *:80>
ServerName captiveportal
ProxyPass / http://ip:port/path
ProxyPassReverse / http://ip:port/path
</VirtualHost>
Now i want to reirect this request to https
How can i achieve this ?
After looking your answer i have changes my configuration like
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "/etc/httpd/conf/crt1.crt"
SSLCertificateKeyFile "/etc/httpd/conf/key1.key"
ProxyPass / http://ip:port/path
</VirtualHost>
<VirtualHost *:80>
ServerName captiveportal
Redirect / https://ip:port/path
</VirtualHost>
but when i type captiveportal on my browser it redirects me on url https://ip:port/path and it displays problem loading page
One more thing i don't want to display https://ip:port/path on browser.
Note :- https://ip:port/path where port is my tomcat port and ip is machine ip where tomcat run.
You could do something like this:
<VirtualHost *:80>
ServerName captiveportal
Redirect / https://my.host.name/
</VirtualHost>
...and then put your ProxyPass directives in side your SSL VirtualHost block instead.