Apache2 route to a different folder based on location match - apache2

I would like to reroute my apache to a different system folder.
Currently I have this setting
<VirtualHost *:443>
ServerName blaah.com
SSLCertificateFile /etc/ssl/certs/blaah.crt
SSLCertificateKeyFile /etc/ssl/private/blaah.key
SSLCertificateChainFile /etc/ssl/certs/DigiCertCA.crt
DocumentRoot /var/www/blaah
Alias /webalizer /var/www/webalizer
<Directory /var/www/webalizer>
Allow from 192.168.0.0/16
Deny from all
AuthType Basic
AuthName webalizer
AuthUserFile /var/www/webalizer/.htpasswd
Require valid-user
</Directory>
ProxyPass /gogs http://127.0.0.1:3000
<LocationMatch "^/blaah/blaah/">
Deny from all
</LocationMatch>
<LocationMatch "^/maintenance">
Allow from IP
Deny from all
</LocationMatch>
</VirtualHost>
So basically when going to servername blaah.com you get directed to a service.
Now I want to do a maintenance on that service, that means I have to reroute them.
But I want to test out that endpoint, so when you write blaah.com/maintenance (the last Location Match should cover that) you get directed to /var/www/maintenance. That folder holds a single index.html that tells you that an maintenance is underway. How can I accomplish that?
In nginx I would do multiple locations and then change document root and tryfiles.

Figured it out.
Used
Alias /maintenance /var/www/maintenance
<Directory /var/www/maintenance">
Allow from IP
</Directory>

Related

setup apache reverse proxy from localhost to domain.com/etherpad

Good evening,
I am trying to set up my apache2 reverse proxy
(following https://github.com/ether/etherpad-lite/wiki/How-to-put-Etherpad-Lite-behind-a-reverse-Proxy)
for etherpad lite
(following https://www.howtoforge.com/tutorial/ubuntu-etherpad-editor-server-installation/, except for the nginx part).
I use http->ssl redirection. Since I use letsencrypt I can only access domain.com and not etherpad.domain.com (at least firefox won't let me and I want to avoid changing that certificate each time I add a new site). So I would like to access my etherpad just as I do access my other sites: domain.com/etherpad. However I always get a 404 trying to get to the site. Looking at a working example, in my nextcloud.conf file I have a line saying:
Alias /nextcloud /local/path/to/nextcloud
However the etherpad reverse proxy virtual host file looks entirely different, the key difference is etherpad not having a local folder but only a mysql database. (Please correct me if this is wrong)
So I tried changing the ssl example from the second link to the following, but it does not work. Please understand that I changed domain name and some internal paths, but "apache2ctl configtest" succeeds and the service is running without error.
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName randomisedDomain.com/etherpad
# SSL configuration
SSLEngine on
# If you hold wildcard certificates for your domain the next two lines are not necessary.
SSLCertificateFile "/working/path/to/fullchain.pem"
SSLCertificateKeyFile "/working/path/to/privkey.pem"
ProxyVia On
ProxyRequests Off
ProxyPreserveHost on
<Location />
AuthType Basic
AuthName "Welcome to the randomisedDomain.com Etherpad"
AuthUserFile /working/path/to/etherpad.passwd
#AuthGroupFile /path/to/svn.group
Require user etherpad
ProxyPass http://localhost:9001/ retry=0 timeout=30
ProxyPassReverse http://localhost:9001/
</Location>
<Location /socket.io>
# This is needed to handle the websocket transport through the proxy, since
# etherpad does not use a specific sub-folder, such as /ws/ to handle this kind of traffic.
# Taken from https://github.com/ether/etherpad-lite/issues/2318#issuecomment-63548542
# Thanks to beaugunderson for the semantics
RewriteEngine On
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:9001/socket.io/$1 [P,L]
ProxyPass http://localhost:9001/socket.io retry=0 timeout=30
ProxyPassReverse http://localhost:9001/socket.io
</Location>
<Proxy *>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Proxy>
</VirtualHost>
Any help for rerouting the localhost domain to randomisedDomain.com/etherpad is greatly appreciated !
Best regards
MAPster

Can't access index.php after modifying the 000-default.conf to suit dms setup

So I've been trying to install Seeddms. I just re-flashed the os on my current samba server and wanted to add this DMS to just make life easier. I've flowed the steps mentioned on this website (Install Guide for old Seeddms). I am aware that this is for the old version of Seeddms and have changed all the version related code.
Question is...
What haven't I done to allow access to the index.php page after modifying the 000-default.conf ?
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory />
Require all granted
</Directory>
Alias /seeddms “/home/www-data/seeddms50x/seeddms-5.0.8/“
<Directory "/home/www-data/seeddms50x/seeddms-5.0.8/">
DirectoryIndex index.php
AllowOverride All
Order deny,allow
Deny from all
Allow from all
</Directory>
</VirtualHost>
Located in -> "/etc/apache2/sites-enabled/"
I try and access the install page using the web address of
http://steve/seeddms/install
(**steve being the name of the samba server)
However, no luck.
Any Ideas ?

Get Apache VHost to load index.html instead of web directory

I'm having no luck finding this question answered so I'm asking this myself.
To get my VHost working, I followed this answer. My (working) "httpd-vhosts.conf" file looks like this
<VirtualHost *:80>
ServerAdmin jesuscc1993#gmail.com
DocumentRoot "Z:/Projects/Web/MetalTxus Site"
ServerName metaltxus.test
ServerAlias www.metaltxus.test
<Directory "Z:/Projects/Web/MetalTxus Site">
#Options FollowSymLinks
Options Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
As far as I know, I should change "Indexes" with "-Indexes" to make the web load "index.html" instead of the web directory.
However, when I did that, my WAMPServer wouldn't start. It would if I removed "FollowSymLinks" option but then all I got was a "403 - Forbidden" page ("you don't have permission to access "/" on this server").
As looking for a solution got me nowhere, I used this as my last resource.
I'm using latest WampServer version in Windows 8.1. I want to test an AngularJS application.
If you need any more information, go ahead and ask.
Try this :-
<VirtualHost *:80>
ServerAdmin jesuscc1993#gmail.com
DocumentRoot "Z:/Projects/Web/MetalTxus Site"
ServerName metaltxus.test
ServerAlias www.metaltxus.test
<Directory "Z:/Projects/Web/MetalTxus Site">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
The Require all granted is Apache 2.4 syntax where you were using Apache 2.2 syntax when using
Order deny,allow
Allow from all
Now all you need to do is place a file called index.html or index.php in the "Z:/Projects/Web/MetalTxus Site" folder.
I would suggest removing the space in the folder name MetalTxus Site its not absolutely necessary but it removes another possible complexity.
Also if you dont actually mean to give access to the site to The Universe try using
Require local
And if you want to be able to access the site just from other PC's on your internal network use
Require local
Require ip 192.168.1
ADDITIONAL SUGGESTION:
Also check httpd.con has thi sline uncommented
LoadModule dir_module modules/mod_dir.so
An has this
<IfModule dir_module>
DirectoryIndex index.php index.php3 index.html index.htm
</IfModule>

Apache2 - Error 403 forbidden

I develop projects that I've located in /home/user/projects directory. This directory is chmod 777. The problem is that I'm always getting Error 403 Forbidden when I try to access this directory or any subdirectory. This is how my /etc/apache2/sites-available/000-default.conf looks like:
<VirtualHost *:80>
ServerName localhost
ServerAdmin user#user.com
DocumentRoot /home/user/projects
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Options +FollowSymLinks
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /home/gtakacs/projects>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
Require all granted
</Directory>
</VirtualHost>
What's wrong with this? When I used /var/www as my document root, everything worked.
EDIT : try doing chmod -R 777 /home to make sure all your home is available (note that this solution is NOT RECOMENDED, having your project in /var/www would definitely be a better solution in my opinion)
(Can't comment so post reply)
Isn't there a config file in your project where you're supposed to set who can access the app? Check if you didn't forget to add your ip adress and domain name in this file.
When using Apache2 with Django framework (python), I had the same error, and it was because I forgot to add the domain name to authorized hosts.
You can also check access.log and error.log to have more detailed informations on what caused the error.
Command out:
#Order allow,deny
I had this issue before, the problem might be that your document root does not contain the described directories.

Test mobile website

I am developing a mobile website and so far I have been testing it in Chrome. Now I would like to test it on my phone.
I am using WAMP and in my hosts file I have the following:
127.0.0.1 www.mysite.com
In my httpd.conf:
<Directory />
AllowOverride All
Require all granted
</Directory>
<VirtualHost *:80>
ServerName www.mysite.com
DocumentRoot "D:/Path/to/website/root"
DirectoryIndex index.php
</VirtualHost>
What should I type in my mobile browser to hit this website? Do I need to change some WAMP settings or anything else?
Add a rule to httpd.conf or to an alias file for your project:
<Directory "D:/Path/to/website/root">
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from 192.168.1.
</Directory>
MAke sure you restart apache after chaging configuration to see the effects. You may also need to put WAMP "Online" by clicking on the icon in the system tray and choosing "Put Online".
Then try accessing you page using the host computer's local IP address.

Resources