403 error through Apache2.4 Directory Alias: what's wrong? - apache2

I ask for some help to keep hairs on my head :D
More seriously, I tried a lot "solutions" found on different posts on different forums, without any result so I need a clean and fresh point of view...
So : I run a JEE application with Apache 2.4 and Tomcat 9 with mod_jk.
To avoid to store heavy content like video in my JEE webapp I created a directory on my server dedicated to some static content.
To do that I try to set a directory alias in my apache vhost, but I get 403 error.
You will find my vhost below, with an alias from /video to /etc/mondir/video (I tried with or without ending /)
I tried a lot of Directory directives without result
Apache2 owned the targeted directory trough www-data user
I also tried to declare the directory alias in etc/apache2/mods-available/alias.conf : not better.
I have no more idea and find no mode idea on the Internet.
Could you please give me some clue? help? advise?
Thank a lot !
<VirtualHost *:443>
ServerName mondomaine.com
ServerAlias www.mondomaine.com
ServerAdmin webmaster#localhost
#DocumentRoot /var/www
DocumentRoot /etc/mondir/
<Directory /etc/mondir/>
Options FollowSymLinks
AllowOverride None
</Directory>
#Add acces to static ressource in /etc/mondir
Alias "/video" "/etc/mondir/video"
Alias "/moncontext/video" "/etc/mondir/video"
<Directory "/etc/mondir/video">
#Options Indexes MultiViews FollowSymLinks
#AllowOverride None
#Order allow,deny
#Allow from all
#Options FollowSymlinks
#AllowOverride None
#Require all granted
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mondomaine\.com
RewriteRule ^video/(.*) /video/$1 [L,QSA]
RewriteRule ^video(.*) /video/$1 [L,QSA]
RewriteRule ^moncontext/(.*) /moncontext/$1 [L,QSA]
RewriteRule ^moncontext(.*) /moncontext/$1 [L,QSA]
RewriteRule ^(.*) /moncontext/$1 [L,QSA]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mondomaine.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mondomaine.com/privkey.pem
JkMount /moncontext/* ajp13_worker
</VirtualHost>

The good directive is "Require all granted"
But, above all, the problem and the solution is on mod_rewrite side.
By default, the rewrite doesnt reach the filesystem, only URI.
Rewrite rule must have the Pass Through option (PT flag) to be seen by the Dir Alias.
More information on mod_rewrite documentation : it's written and simple if you know where to read.
Thank all,

Related

Adding WWW in Domain?

my website hosted on ec2 - AWS. I want to add www in my website. Also my website has ssl. I am not able to add www in my website. I want my website full domain should be start with https://www.
I installed ubantu.
First, connect to your ec2 instance using ssh
After connect successfully go to your root directory using sudo su -
After that run sudo nano /etc/apache2/sites-available/000-default.conf to open your config file.
then in your vi editor you have to write below code
ServerName yourdomain.com
ServerAlias www.yourdomain.com
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
save the file.
And restart your apache server using
service apache2 restart.
Hope this will help you.

React-router typed-url and refresh on tomcat, elastic beanstalk

There are a lot of questions about this topic which is that typed URL and refresh do not work when using react on production but I'm trying for a long time now and for some reason it does not work.
I'm using React with Spring boot and tomcat. I am using BrowserRouter for routing. I deploy the application on aws elastic beanstalk. When I deploy, I do the following:
run npm run build then copy the resulting files in build folder into webContent folder then export project as war file and deploy it to aws.
As I understood, the main solution for this is to server the index.html file for all requests and I tried the following to do that:
- add the following to /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
DocumentRoot /var/lib/tomcat8/webapps/ROOT/
ServerName domain.elasticbeanstalk.com
AliasMatch ^/(.*)$ /var/lib/tomcat8/webapps/ROOT/index.html
<Directory "/var/lib/tomcat8/webapps/ROOT">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^/(.*)$ - [L]
RewriteRule ^/(.*)$ /index.html [L]
</Directory>
</VirtualHost>
From the questions I read, it is suggested to use /var/www/html but I did not get why. I tried to use it by copying everything from ROOT to it but also did not work.
I tried many variations to the code I put in the configuration file.
With the configuration, I get the error
SyntaxError: expected expression, got '<'.
On firefox, I get The script from “http://awsdomain.com/static/js/2.7322c0fb.chunk.js” was loaded even though its MIME type (“”) is not a valid JavaScript MIME type.
and on chrome I get same error but with css files and not js.
At this point, I assume the serving of index.html is working but there is another issue that the server is trying to parse some js or css files like html or text which would not work. In any case, I have no idea how to tell the browser to parse them in the right way and why is it parsing them with no errors in the normal way (without solving the routing issue)?
I tried to add type attribute to link and script tags in index.html but did not work.
There are many stuff I tired specially in the config files on aws instance but it would be hard to put it all here. I'm hoping from the comments to get the root of the problems and then I can give any missing information.
My problem is finally fixed.
The following is my final addition to the httpd.conf
<VirtualHost *:80>
DocumentRoot /var/lib/tomcat8/webapps/ROOT/
ServerName domain.elasticbeanstalk.com
<Directory /var/lib/tomcat8/webapps/ROOT>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
DirectoryIndex index.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
</Directory>
</VirtualHost>
Also, it was annoying that dir_module was not included by default which is needed by DirectoryIndex. To include it, add LoadModule dir_module modules/mod_dir.so.

Error with apache virtual host configuration for symfony project

I created the project using Symfony framework, and when I am runing build in server in prod or dev env runs ok, But now I move project to debian server, install apache and create virtual host. It shows only directory list and not starts the app. I think that is something wrong with my virual host configuration. I am using Apache/2.4.10 (Debian) Server, PHP 5.6.19-0+deb8u1 (cli).
Here is the code for virtual host:
<VirtualHost *:80>
ServerName mose
ServerAlias 10.5.0.62
DocumentRoot /var/www/mose/web
<Directory /var/www/mose/web/>
AllowOverride None
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeScript assets
# <Directory /var/www/mose>
# Options FollowSymlinks
# </Directory>
# optionally disable the RewriteEngine for the asset directories
# which will allow apache to simply reply with a 404 when files are
# not found instead of passing the request into the full symfony stack
<Directory /var/www/mose/web/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
The right answer was AllowOverride All from Dawid Sajdak. Tnx for help

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 vhost redirection

I have defined differents hosts in my windows host file, one for every project release (rc1, rc2 etc..)
I would like to create one vhost per release so I can redirect directly to its subdir, for example :
pp15.mv => http://localhost/mv/pp15/.....
pp16.mv => http://localhost/mv/pp16/.....
moreover, I need to redirect the host ppX.mv to an autologin url, something looks like /mv_dbname.php?login=testlogin&mdp=202cb962ac59075b964b07152d234b70
so, finally, I want to type this in my urlbar :
http://pp15.mv
and get redirected to
http://pp15.mv/mv_dbname.php?login=testlogin&mdp=202cb962ac59075b964b07152d234b70
In my virtual host file I have something like this :
<VirtualHost *:80>
ServerName pp15.mv
DocumentRoot "D:\apache\htdocs\mv\pp15"
<Directory "D:\apache\htdocs\mv\pp15">
AllowOverride All
Allow from All
</Directory>
RewriteEngine On
RewriteRule ^/index.php /myvisitv3_dbname.php?login=johsmi&mdp=202cb962ac59075b964b07152d234b70 [R]
RewriteRule ^(/)?$ /myvisitv3_dbname.php?login=johsmi&mdp=202cb962ac59075b964b07152d234b70 [R]
</VirtualHost>
The first redirection works great, but if i try to redirect directly the host, I get a redirection error (too many redirections occured)
Do someone have an idea ?
Thank you previously.
ok, finally here what I did :
<VirtualHost *:80>
ServerName pp16.mv
RewriteEngine on
RewriteCond %{HTTP_HOST} ^pp16\.mv$
RewriteRule ^(/)?$ /mv/pp16/xxx/xxx_dbname.php?login=johsmi&mdp=202cb962ac59075b964b07152d234b70 [R]
</VirtualHost>
no [L] on redirection because app have internal redirection, and no document root because php won't be able to read $_SERVER['REQUESTED_URI'] var correctly, so I could have did this (I prefer)
<VirtualHost *:80>
ServerName pp16.mv
DocumentRoot "D:\apache\htdocs\mv\pp16\xxx"
RewriteEngine on
RewriteCond %{HTTP_HOST} ^pp16\.mv$
RewriteRule ^(/)?$ /xxx_dbname.php?login=johsmi&mdp=202cb962ac59075b964b07152d234b70 [R]
</VirtualHost>
but php would have misread the app path (/ instead of /mv/pp16/xxx/)

Resources