Error with subdomain basic authentication via htpasswd - laravel

Issue:
I have Laravel running on Apache 2.4.9 and my domains are organized as follows:
beta.domain.com => /var/www/beta
www.domain.com => /var/www/live
The beta subdomain has basic authentication. Everything is working as expected except when I started poking around the apache2 error logs. I get the following error message:
AH01797: client denied by server configuration:
/var/www/beta/public/index.php, referer: https://beta.domain.com/
My setup:
Here is my setup:
<VirtualHost *:80>
# Redirect all http traffic to https
Redirect 301 / https://www.domain.com/
</VirtualHost>
<VirtualHost *:443>
# some SSL setup for www here
ServerName www.domain.com
DocumentRoot /var/www/live/public
<Directory /var/www/live/public>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SetEnv ENVIRONMENT "live"
</VirtualHost>
<VirtualHost *:443>
# some SSL setup for beta here
ServerName beta.domain.com
DocumentRoot /var/www/beta/public
<Directory /var/www/beta/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
# allow from one ip
Allow from xxx.xxx.xxx
Satisfy any
AuthUserFile /path/to/htpasswd/.htpasswd
AuthName "Password required"
AuthType Basic
Require valid-user
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SetEnv ENVIRONMENT "beta"
</VirtualHost>
Failed attempts:
I've found several differing answers for this, none of which worked for me. These are the ones that seem the most convincing, but again they didn't work for me.
Replacing <Directory> with <Location> tags (http://httpd.apache.org/docs/current/mod/mod_auth_basic.html#authbasicprovider) - the errors were gone, but I lost basic authentication
Using Require all granted instead of Order allow/deny - this also
removed basic authentication for me. Also not sure if this makes
sense in my scenario.

Because I'm using Apache 2.4+, I changed
Order allow, deny
Allow from all
to simply
Require all granted
This fixes the error message, but to allow for basic authentication on the beta subdomain, I also had to remove Satisfy any
So the set up for beta would be changed to this:
<Directory /var/www/beta/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
# removed in 2.4
# Order allow,deny
# allow from one ip
Require ip xxx.xxx.xxx
# No longer require Satisfy any in 2.4
# Satisfy any
AuthUserFile /path/to/htpasswd/.htpasswd
AuthName "Password required"
AuthType Basic
Require valid-user
</Directory>

Related

Laravel 8 does not know route other than "/" on the server

I am experiencing a problem when uploading laravel 8 to the service, it is only recognizing the "/" route and nothing else, then I am receiving the following error "The requested URL was not found on this server."
However if I indicate "domain/index.p/route", then it works normally, I saw several articles indicating that it was on apache2 in the .conf file but I couldn't configure it in case I'm using debian on EC2.
How could I be solving this issue?
.conf file
<VirtualHost *:80>
ServerAdmin webmaster
DocumentRoot /var/www/directory/public
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/directory>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

deploy multiple laravel projects in apache virtual hosts

I have two laravel projects, I deploy on VPS, then I configure the apache virtual host for each project in my /etc/apache2/sites-available.
example:
project1.conf:
Listen 8999
NameVirtualHost *:8999
<VirtualHost *:8999>
ServerName project1.test
ServerAlias www.project1.test
DocumentRoot "C:/laragon/www/data/project1/public"
DirectoryIndex index.php
<Directory "C:/laragon/www/data/project1/public/">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
project2.conf
Listen 8998
NameVirtualHost *:8998
<VirtualHost *:8998>
ServerName project2.test
ServerAlias www.project2.test
DocumentRoot "C:/laragon/www/data/project2/public"
DirectoryIndex index.php
<Directory "C:/laragon/www/data/project2/public/">
#Options Indexes FollowSymLinks MultiViews
AllowOverride All
#Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
in my /windows/system32/drivers/etc/host, I have already made a host for each project.
but I have a problem, which is when I open the first project in the browser and log in, then at the same time I open the second project and login too, when the first project is refreshed, it returns to the login page. Why did it happen ?
Instead of doing it the hard way, you can try to use Laravel Valet, which allows you to link your site to a domain like localhost.test and localhost2.test. It takes care of all virtual host configuration.

How to access a laravel api in apache virtual host?

I have set up apache virtual host and have a site with below config (the website is working well):
NB: The domain names below fictitious.
<VirtualHost *:80>
ServerName www.bill.test.com
ServerAlias bill.test.com
Redirect / https://bill.test.com/
</VirtualHost>
<VirtualHost *:443>
ServerName www.bill.test.com
ServerAlias bill.test.com
DocumentRoot /applications/www/bill.test.com/public_html/public
SSLEngine on
SSLCertificateFile /home/user1/ssl_certificate/test.com/wildcard_eneoapps_com.crt
SSLCertificateKeyFile /home/user1/ssl_certificate/test.com/wildcard_eneoapps_com.key
SSLCertificateChainFile /home/user1/ssl_certificate/test.com/DigiCertCA.crt
ErrorLog /applications/www/bill.test.com/error.log
CustomLog /applications/www/bill.test.com/requests.log combined
<Directory "/applications/www/bill.test.com/public_html/public">
AllowOverride All
</Directory>
</VirtualHost>
Also, on this server I have an API located in the directory below:
/applications/www/html/ebill-api
Now when I try to call this API in the code, I get the error below:
Client error: `POST http://12.ipp.106.21/ebill-api/public/api/login' resulted in a `404 Not Found` response:\n
My httpd.conf file looks like below:
DocumentRoot "/applications/www/html"
#
# Relax access to content within /var/www.
#
<Directory "/applications/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
# Further relax access to the default document root:
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
Please help as I am new to configuring apache and confuse why this doesn't work. I was able to call an API on a separate
server but I don't understand why calling this one which is on thesame server as the website is not working.
Since you have the Laravel api in a subfolder, you should adjust the APP_URL in your .env file to be http://12.ipp.106.21/ebill-api/public/
Try this change. See if it help.

How to serve different web apps using one domain name in Apache?

I'm currently trying to deploy my Django 2.0 App on an Apache Web Server. However I'm experiencing difficulties in configuring it because my Virtual Host configuration overrides other Virtual Hosts which is used by other projects (Ruby and PHP WebApps). We only have one domain name at the moment so I cannot use other domain names to host my app.
Is it possible to serve different kind of apps with one domain name using Apache Virtual Hosts?
Since you can only have 1 VirtualHost (one domain, one port, one IP), you cannot create additionnal VH. You need to "split" the paths to the different applications some other way.
Let assume www.example.com:
ServerRoot "/some/path/apache"
[...] OTHER LoadModule directives [...]
LoadModule alias_module modules/mod_alias.so
Listen *:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
# Logs
LogLevel warn
CustomLog "logs/www.example.com_access-log" combined
ErrorLog "logs/www.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This VirtualHost is a basic configuration for the www.example.com domain. Now you want to have Ruby, PHP WebApps and Django 2.0 App under that single domain. You have 3 choices:
Get 1 domain per application, not applicable here, that is your question.
Make a sub-directory in htdocs, and a path in the URI for each application.
Put each application in some directory, not under DocumentRoot and use Alias.
Use sub-domains.
Not applicable.
Sub-directory and path
Create /some/path/apache/htdocs/Ruby, put your Ruby app. here.
Will be accessed via http://www.example.com/Ruby
Create /some/path/apache/htdocs/PHPWebApps, put your PHP app. here.
Will be accessed via http://www.example.com/PHPWebApps
Create /some/path/apache/htdocs/Django, put your Django app. here.
Will be accessed via http://www.example.com/Django
The URI value must match the directory value.
In some directory, use Alias
If you do not need, or want the URI to match the directory name (like in 2.), use Alias.
Create /SOME_DIR_FOR_Ruby, put your Ruby app. here.
Add Alias "/Ruby" "/SOME-DIR-FOR-Ruby"
Will be accessed via http://www.example.com/Ruby
Create /SOME_DIR_FOR_PHPWebApps, put your PHP app. here.
Add Alias "/PHPWebApps" "/SOME_DIR_FOR_PHPWebApps"
Will be accessed via http://www.example.com/PHPWebApps
Create /SOME_DIR_FOR_Django, put your Django app. here.
Add Alias "/Django" "/SOME_DIR_FOR_Django"
Will be accessed via http://www.example.com/Django
Use sub-domains
This is where you could use multiple VirtualHosts. But you have to be able to create sub-domains. This is done either via a DNS configuration, or through your hosting provider.
You could setup http://ruby.example.com, http://php.example.com, http://django.example.com. Each of these will have 1 VirtualHost, but will all be mapped to the same IP in the DNS.
Then setup 3 VH:
<VirtualHost *:80>
ServerName ruby.example.com
# Logs
LogLevel warn
CustomLog "logs/ruby.example.com_access-log" combined
ErrorLog "logs/ruby.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/Ruby"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/Ruby">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName php.example.com
# Logs
LogLevel warn
CustomLog "logs/php.example.com_access-log" combined
ErrorLog "logs/php.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/php"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/php">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName django.example.com
# Logs
LogLevel warn
CustomLog "logs/django.example.com_access-log" combined
ErrorLog "logs/django.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/django"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/django">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
On Apache 2.2, you have to add NameVirtualHost *:80, in Apache 2.4, nothing, it is always "on".
All these values can be changed as you like, this is just an example to explain the concept.

WAMP 3.06, is Directory into Virtual Hosts broken?

I am using WAMP 3.06. I have a web site hosted in "c:/wamp64/www/webagenda"
When I try to access the site remotely using "http://cloudappoint.myvnc.com", I get:
Forbidden
You don't have permission to access /webagenda on this server.
Apache/2.4.23 (Win64) PHP/5.6.25 Server at agenda.myvnc.com Port 8000
My virtual host file is:
# Virtual Hosts
<VirtualHost *:8000>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
#if I uncomment the next lines the problem is over
#<Directory "c:/wamp64/www/webagenda">
#Options Indexes FollowSymLinks Includes ExecCGI
#DirectoryIndex index.php
#AllowOverride None
#Require all granted
#</Directory>
<VirtualHost *:8000>
ServerName cloudappoint
ServerAlias cloudappoint.myvnc.com
DocumentRoot c:/wamp64/www/webagenda
ErrorLog "logs/agenda-error.log"
CustomLog "logs/agenda-access.log" common
<Directory "c:/wamp64/www/webagenda/">
Options +Indexes +FollowSymLinks +MultiViews
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
As you can see from my comments, if I I uncomment the next lines the problem is over:
<Directory "c:/wamp64/www/webagenda">
Options Indexes FollowSymLinks Includes ExecCGI
DirectoryIndex index.php
AllowOverride None
Require all granted
</Directory>
What is wrong here, please?
If moving the <Directory> block out of the <VirtualHost> block causes access to be allowed then it is a fair assumption that there is something wrong with the <VirtualHost> definition.
Can I suggest that you try this change in your definition
<VirtualHost *:8000>
ServerName cloudappoint.myvnc.com <--change
ServerAlias www.cloudappoint.myvnc.com <--change
DocumentRoot c:/wamp64/www/webagenda
ErrorLog "logs/agenda-error.log"
CustomLog "logs/agenda-access.log" common
<Directory "c:/wamp64/www/webagenda/">
Options +Indexes +FollowSymLinks +MultiViews
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EDIT
I assume you are adding the non standard port number to the url when trying to access the site?
http://cloudappoint.myvnc.com:8000
When I add the :8000 I do not get the error I get an offline page saying
The site you have requested is currently unavailable,
please try back again later.

Resources