I am trying to use a virtualhost with an alias to deploy a Laravel application.
Using apache2 in ubuntu 16.04.
My 000.conf file is:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options -Indexes
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/public
Alias /expediente "/var/www/public/"
<Directory /var/www/public/>
Options -Indexes
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
The first one is working ok but the second one does not.
What am I doing wrong?
==============
EDIT
Ok so i made two conf files in sites available and symlinked them to sites-enabled.
advanced.conf
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName ip-address:80/advanced
ServerAlias /advanced
DocumentRoot /var/www/html/advanced
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
expediente.conf
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName ip-address:80/expediente
ServerAlias /expediente
DocumentRoot /var/www/html/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Reloaded and restarted apache2.
If i try to navigate to ip-address/ i get the first page, the advanced,
If i try to navigate to ip-address/advanced 404 not found
If i try to navigate to ip-address/expediente 404 not found
What am i doing wrong?
its good practice create different host file for your alias. you can use this command to copy default config for your second alias with this command
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
and open it in whichever editor you like and put this content
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
save and close the file then run this command
sudo a2ensite example.com.conf
and restart your apache
You gonna need ServerName in your virtual hosts configurations, its probably always defaulting to the first one without that. For example
ServerName mydomain.net
Si tus proyecto esta de la forma http://localhost/AppName, entonces debes colocar en el httpd.conf
<VirtualHost site1.local:80>
ServerAdmin webmaster#example.com
DocumentRoot /path/to/htdocs/site1
ServerName www.site1.local
ServerAlias site1.com
</VirtualHost>
y el segundo.
<VirtualHost site2.local:80>
ServerAdmin webmaster#example.com
DocumentRoot /path/to/htdocs/site2
ServerName www.site2.local
ServerAlias site2.com
</VirtualHost>
Related
Hi I have browsed all the resources, but still seems can't find the solution.
I have XAMPP Control Panel v 3.2.4 (compiled Jun 5th 2019) installed on my computer, it is installed in d:\xampp. I want to create a Virtual host, so that I can correctly use various global PATH variables.
I followed instructions closely.
This is from my D:\xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:\xampp\htdocs"
<Directory "D:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName ikeen.localhost
DocumentRoot "D:\xampp\htdocs\ikeen"
SetEnv APPLICATION_ENV "development"
<Directory "D:\xampp\htdocs\ikeen">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I have added following lines to the end of httpd.conf:
<Directory />
AllowOverride none
Require all granted
</Directory>
I have the following line in my hosts file in windows:
127.0.0.1 ikeen.localhost
This is the structure of my site directory
In order to avoid cache I open URL in the incognito mode and from different browsers. I always get redirect to dashboard - https://ikeen.localhost/dashboard/, it opens the standard "Welcome to XAMPP for Windows 7.4.3"
I have heard that it has something to do with https, as I'm always transferred to https URL even if I try to use http. I've looked at httpd-ssl.conf, but I don't know what to do there. Any ideas?
Finally! For everyone who is looking for the solution do the following:
My desired site is located at D:\xampp\htdocs\ikeen.
1) Add this to your httpd-vhosts.conf:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:\xampp\htdocs"
<Directory "D:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName ikeen.localhost
DocumentRoot "D:\xampp\htdocs\ikeen"
SetEnv APPLICATION_ENV "development"
<Directory "D:\xampp\htdocs\ikeen">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
2) Add this to the end of httpd.conf:
<Directory />
AllowOverride none
Require all granted
</Directory>
3) Add this line to your hosts file in Windows directory
127.0.0.1 ikeen.localhost
4) Finally, this is the step that is missing from all the solutions. Add this to your httpd-ssl.conf, after the same section for your localhost (usually www.example.com), change example.com to your local settings for localhost, so that the whole section looks smth like this
<VirtualHost _default_:443>
# General setup for the virtual host
DocumentRoot "D:/xampp/htdocs"
#ServerName www.example.com:443
ServerName localhost
ServerAdmin admin#example.com
ErrorLog "D:/xampp/apache/logs/error.log"
TransferLog "D:/xampp/apache/logs/access.log"
# General setup for the ikeen host
DocumentRoot "D:/xampp/htdocs/ikeen"
#ServerName www.example.com:443
ServerName ikeen.localhost
ServerAdmin admin#example.com
ErrorLog "D:/xampp/apache/logs/error.log"
TransferLog "D:/xampp/apache/logs/access.log"
I had the same issue. Problem was solved by removing the standard virtual host entry and i wasn't redirected to the root directory.
Just remove these lines of code:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:\xampp\htdocs"
<Directory "D:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
If the case does not work, maybe change httpd-ssl.conf
My 3 sites worked, localhost, test1.com, test2.com
#
<VirtualHost _default_:443>
DocumentRoot "c:/xampp/htdocs"
ServerName localhost
ServerAdmin admin#example.com
ErrorLog "c:/xampp/apache/logs/error.log"
TransferLog "c:/xampp/apache/logs/access.log"
...
</VirtualHost>
#test1
<VirtualHost _default_:443>
DocumentRoot "c:/xampp/htdocs/test1"
ServerName test1.com
ServerAdmin admin#example.com
ErrorLog "c:/xampp/apache/logs/error.log"
TransferLog "c:/xampp/apache/logs/access.log"
...
</VirtualHost>
#test2
<VirtualHost _default_:443>
DocumentRoot "c:/xampp/htdocs/test2"
ServerName test1.com
ServerAdmin admin#example.com
ErrorLog "c:/xampp/apache/logs/error.log"
TransferLog "c:/xampp/apache/logs/access.log"
...
</VirtualHost>
I've created a Laravel Project, which I have deployed previously with apache2, and working great.
As I finished with my latest deployment, I found that no external CSS was being loaded when I was done with. So I did a check on all step many times over, but I don't think I have missed on anything.
However, upon running with php artisan serve everything works fine.
Here is my virtual_host config file:
<VirtualHost *:80>
ServerAdmin admin#project
DocumentRoot /var/www/html/project/public/index.php
ServerName example.com
ServerAlias www.example.com
DirectoryIndex index.php
<Directory /var/www/html/project/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
In virtualhost configuration, you should try using
<VirtualHost *:80>
ServerAdmin admin#project
DocumentRoot /var/www/html/project/public
ServerName example.com
ServerAlias www.example.com
DirectoryIndex index.php
<Directory /var/www/html/project/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Remove public folder from <Directory> and also remove index.php from DocumentRoot.
I'm attempting to setup a local development server where I can simply access any project within a directory E:\development\projects\ and have apache automatically redirect me to the correct subdomain.
However when attempting to redirect to a sub-subdomain (backend.project01.dev01), I simply get a "server unreachable" message.
See my httpd-vhosts.conf for more info:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName dev01
ServerAlias www.dev01
DocumentRoot "E:\development\projects"
ErrorLog "logs\errors.log"
<directory "E:\development\projects">
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName dev01
ServerAlias *.dev01
VirtualDocumentRoot "E:\development\projects\%1"
ErrorLog "logs\errors.log"
<directory "E:\development\projects\%1">
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName dev01
ServerAlias *.*.dev01
VirtualDocumentRoot "E:\development\projects\%2"
ErrorLog "logs\errors.log"
<directory "E:\development\projects\%2">
</directory>
</VirtualHost>
In a nutshell:
This work:
project01.dev01/
This doesn't work:
backend.project01.dev01/
So I've found a solution. To match sub-subdomains, you have to match the deepest level first.
I.e.: match deepest.sub.domain before sub.domain
The answer in this example is:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName dev01
DocumentRoot "E:\development\projects"
ErrorLog "logs\errors.log"
<directory "E:\development\projects">
</directory>
</VirtualHost>
## moved this up
<VirtualHost *:80>
ServerName dev01
ServerAlias *.*.dev01
VirtualDocumentRoot "E:\development\projects\%2"
ErrorLog "logs\errors.log"
<directory "E:\development\projects\%2">
</directory>
</VirtualHost>
## moved this down
<VirtualHost *:80>
ServerName dev01
ServerAlias *.dev01
VirtualDocumentRoot "E:\development\projects\%1"
ErrorLog "logs\errors.log"
<directory "E:\development\projects\%1">
</directory>
</VirtualHost>
In this example apache will always first attempt to match the *.*.dev01 and if it fails, attempt to match *.dev01.
Hopefully this will help others in the future.
I have a codeigniter site running on a Apache web server
I installed an SSL from letsencrypt
My site works fine if I access it through http://example.com
but,
If I access it through https://example.com the site shows but the database is broken
This is my htaccess file
Include /etc/phpmyadmin/apache.conf
<VirtualHost *:80>
ServerName example.org
ServerAlias www.example.org
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
RewriteEngine on
RewriteRule "^/resources/(.+)" "https://example.org/_resources/$1"$
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ProxyPass /api https://localhost:8010/api
ProxyPassReverse /api https://localhost:8010/api
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.org
ServerAlias www.example.org
DocumentRoot /var/www/html/
Include /etc/letsencrypt/options-ssl-apache.conf
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.org-0001/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.org-0001/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.org-0001/chain.pem
</VirtualHost>
Fixed this issue by adding inside of the <VirtualHost *:443> tag
<Directory /var/www/html>
AllowOverride All
</Directory>
Ive just completed the setup of apache.
Setup looks as follow:
my virtualhost:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName system.local
ServerAlias www.system.local
DocumentRoot /var/www/system
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
My hosts file is:
127.0.1.1 system.local
I have also used a2enmod to enable mod_rewrite.
When i open my application and for instance go to /Admins/index i get a page not found.
Does anyone know what i might be missing?
If you are using an .htaccess file. You need to allow the use of an .htaccess file in your web directory using AllowOverride All. For that your code should look like this.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName learningbank.local
ServerAlias www.learningbank.local
DocumentRoot /var/www/system_learningbank
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/system_learningbank>
AllowOverride All
</Directory>
</VirtualHost>
Also don't forget to restart apache when making config changes.