Exclude an alias from virtualhost proxypass - linux

I've following virtual host configuration. The desired result is:
If someone requests http://test.myserver.com/myapp, apache serves
him from /var/www/myapp
And if http://test.myserver.com/ is
requested, apache redirects it to port 8069.
2nd is working but 1st is not. Can someone help please!
<VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
</VirtualHost>

This is how I was able to achive the desired outcome. Following is the working configuration where ProxyPassMatch ^/myapp ! did the trick and except the (server-address)/myapp, all the requests are being proxying to the other server which is open-erp running at port 8069:
<VirtualHost *:80>
ServerName test.myserver.com
Alias /myapp /var/www/myapp
<Directory /var/www/myapp>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ProxyPassMatch ^/myapp !
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>

Instead of using:ProxyPassMatch ^/myapp ! you could have simply added another ProxyPass directive before the one defining /, like this:
ProxyPass /myapp !
ProxyPass / http://localhost:8069/
Since ProxyPass respects precedence (the first match will be processed), it will correctly redirect to the directory instead of proxying.

in case you have a RewriteCond (which is very likely when you run a proxy) this one will make you happy as well!
<Location /.well-known/acme-challenge/>
RewriteEngine off
ProxyPass !
</Location>

Related

How is it possible to run 2 Websites in 2 different subfolders on one Apache instance?

i just want to run 2 web applications which both are in seperate subfolders.
So Subfolder One (which is the Homepage) should be reachable under : example.com.
While Subfolder two should be reachable under example.com/subfolder .
I know it is somehow possible with the Apache vhosts file, but i am new to this vhost stuff und dont know, how to solve that problem.
Thanks for your help!
i just got it running like that! Is there any reason this could be a problem in sight of security?
<VirtualHost *:80>
ServerName example.com
ServerAdmin example#mail.com
Redirect permanent / https://example.com
DocumentRoot /var/www/webpage/
<Directory /var/www/webpage/>
</Directory>
</VirtualHost>
**And for SSL**
<VirtualHost *:443>
ServerAdmin example#mail.com
ServerName example.com:443
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
</IfModule>
DocumentRoot /var/www/webpage/
<Directory /var/www/webpage/>
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/webpage>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Alias /subfolder /var/www/subfolder/
<Directory /var/www/subfolder>
Order allow,deny
allow from all
</Directory>
SSLCertificateFile /etc/certs/live/**********/fullchain.pem
SSLCertificateKeyFile /etc/certs/live/**********/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

Htaccess doesn't work on MAMP with multiple sites

I have 3 sites on MAMP local server but in 2 of 3, the htaccess doesnt work.
I add this code in httpd.conf (MAMP->apache):
NameVirtualHost *
<VirtualHost *>
DocumentRoot "c:/MAMP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\codes\Bedloop"
ServerName local.bed.com
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\codes\apart"
ServerName local.apart.com
</VirtualHost>
And this lines on windows hosts file:
127.0.0.1 local.bed.com
127.0.0.1 local.apart.com
I put on 3 pages, the same files (same page), but htacces only work on the localhost page, not in other 2. The main page work fine, but urls with rewrite rules fails.
I need to config something more?
Thx!
NameVirtualHost is deprecated. Can you try these directives in your Apache vhost file and restart apache:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "c:\MAMP\htdocs"
<Directory "c:\MAMP\htdocs">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName local.bed.com
DocumentRoot "C:\codes\Bedloop"
<Directory "C:\codes\Bedloop">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName local.apart.com
DocumentRoot "C:\codes\apart"
<Directory "C:\codes\apart">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
</Directory>
</VirtualHost>

Rewrite not working, even though AllowOverride is set to All

I've installed LAMP stack on a digitalocean droplet running on Ubuntu. I have a file called "/restful/post.php".
using "https://url/restful/post.php" works just fine, however, I want to make it SEO friendly, sth like "/restful/post".
my htaccess is in the root folder "html/var/www" and has the following:
RewriteEngine on
RewriteRule ^/restful/post(.*)$ /restful/post.php?p=$1
I have got a2enmode enabled, AllowOverride is set to All in "/etc/sites-available/*".
for the 000-default.conf, I've got:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Redirect / https:/url
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
and for the 000-default-le-ssl.conf, I've got:
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
All the answers to the questions I've seen didn't fix my issue and I'm not really sure what I'm missing here.

Using wordpress for /blog route in nodejs website not working

I created a vhost like this in my apache2 server configuration:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName test.co
ServerAdmin webmaster#localhost
#wordpress
Alias /blog "/var/www/test_wp/public_html"
<Directory "/var/www/test_wp/public_html">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
SSLCertificateFile /etc/letsencrypt/live/test.co/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test.co/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
I'm using alias to redirect /blog url (test.co/blog) to wordpress folder in my server.
i'm using proxypass for the nodejs website.
But when i hit test.co/blog , it shows 404 not found, in my nodejs website
Follow this: Exclude an alias from virtualhost proxypass
Add this line :
ProxyPassMatch ^/blog !
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

Securing apache server Virtual hosts

first off my set up:
Ubuntu Server 11 with full LAMP installed
Sample of my /etc/apache2/sites-available/default
NamevirtualHost *
<VirtualHost *>
ServerName www.web.com
ServerAlias www.web.com
ServerAdmin me.co.uk
DocumentRoot "/var/www/web"
DirectoryIndex index.php
Alias /pdf /var/www/web/pdf/Order_pdf
Alias /glass /var/www/web/pdf/Glass_order_pdf
ErrorLog "/var/www/logs/error.log"
CustomLog "/var/www/logs/access.log" combined
CustomLog "/var/www/logs/deflate.log" deflate
</VirtualHost>
<VirtualHost *>
ServerName www.intranet.com
ServerAlias www.intranet.com
ServerAdmin me.co.uk
DocumentRoot "/var/www/intranet"
DirectoryIndex Search.php
ErrorLog "/var/www/logs/error.log"
CustomLog "/var/www/logs/access.log" combined
CustomLog "/var/www/logs/deflate.log" deflate
</VirtualHost>
I have my router forwarding port 80 to my server and it is correctly showing www.web.com I want to somehow block any external access to the intranet site but not exactly sure how to do this, hope someone can help?
Would this be something I need to use?
<Directory "/var/www/web">
Options Indexes FollowSymLinks
Allow Override None
Order deny,alow
deny from all
allow list 192.168.1.0/24
</Directory>
I'm sure this has been answered elsewhere. Anyway if you want to use IP check on you intranet you can do this.
<Directory /var/www/intranet/>
Order allow,deny
Allow from 192.168.1.0/24
</Directory>

Resources