Apache2 does not serve ServerAlias without www - apache

This is my sites-available/FlaskApp.conf file
<VirtualHost *:80>
ServerName www.mywebsite.design
ServerAlias mywebsite.design
ServerAdmin myemail#gmail.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
www.mywebsite.design works when i open on the browser correctly. However when i go to mywebsite.design the Ubuntu Default "It Works" page shows up.
I followed this tutorial Hosting a FlaskApp
When i tried IPAddress as the Servername like this -
ServerName 139.55.55.55
for some reason the opening the IP address on the browser opens correctly but both www.mywebsite.design or mywebsite.design don't shows the same Ubuntu Default Page

I had mywebsite.design on /etc/hosts like this -
127.0.1.1 mywebsite.design mywebsite
. probably because i named the project that way at some point!
Removed it and just put my name there and it worked!

Related

My website URL with www shows the correct content but shows the Apache2 Ubuntu Default page without www. How do I correct this?

I followed the How To Deploy a Flask Application on an Ubuntu VPS
and How To Install the Apache Web Server on Ubuntu 20.04
from Digital Ocean where my hosting is. I have two type A DNS records set up where the hostname is my URL with www and my URL without it, that direct to the value of my public IP.
I can change which address shows the correct information by changing ServerName to either my public IP, my website with www, or my website without www. How can I make it so that www.mywebsite.com and mywebsite.com both show correctly? A redirect surely can't be the right answer?
Here is the conf file: /etc/apache2/sites-available/FlaskApp.conf
<VirtualHost *:80>
ServerName www.mywebsite.com
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I tried adding a permanent redirect it didn't work.
<VirtualHost *:80>
ServerName www.mywebsite.com
Redirect permanent / http://mywebsite.com/
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
For anyone else with this problem I found a solution by adding a server alias:
<VirtualHost *:80>
ServerName www.mywebsite.com
ServerAlias mywebsite.com
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Change Laravel base URL from localhost to localhost/laravel5

I'm trying to change Laravel base URL to localhost/laravel5, I tried to change APP_URL variable in .env file, I did the same changes to this line in config/app.php file:
'url' => env('APP_URL', 'http://localhost/laravel5')
And here my /etc/apache2/sites-available/laravel.conf file:
<VirtualHost *:80>
ServerName localhost/laravel5
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/laravel5/public
<Directory /var/www/html/laravel5>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I also tried to restart apache2 service, but nothing changes
Make your virtual server like this in apache
<VirtualHost *:80>
ServerName laravel5.app
DocumentRoot /var/www/html/laravel5/public
<Directory /var/www/html/laravel5/public>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and run
sudo a2ensite laravel5.app
service apache2 reload
Finally, make sure to edit your /etc/hosts file and add an entry for laravel5.app:
# other entries...
# your entry...
127.0.0.1 laravel5.app
And then you can access your app at http://laravel5.app
I recommend You to use something like Homestead or Valet for developing Check the docs here

laravel 5.3: setup virtual host. Getting Apache 404 error

I want to setup a virtual host in my localhost, so I can access my Laravel app like this: demo.example.com. I have added a custom conf file: etc/apache2/sites-available/example.com.conf with the following contents:
<VirtualHost *:80>
ServerAdmin username#gmail.com
ServerName example.com
ServerAlias www.example.com
ServerAlias demo.example.com
ServerAlias www.demo.example.com
DocumentRoot /var/www/example/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/example/public>
AllowOverride All
</Directory>
</VirtualHost>
Contents from /etc/hosts file:
127.0.0.1 localhost
127.0.1.1 username-pc
127.0.0.1 example.com
127.0.0.1 www.example.com
127.0.0.1 http://exaple.com
127.0.0.1 demo.example.com
With the above settings if I access the url demo.example.com it works. But if I try to access other routes like demo.example.com/login I get apache 404 error: The requested URL /login was not found on this server. How do I fix this?
Note that this is not laravel's NotFoundHttpException.
place this under your directory tag
<Directory /var/www/example/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

joomla admin in subdomain blank page

I am having trouble accessing the Joomla administrator page in a subdomain.
Here's what it's like, the site is http://test.com and the admin page must be http://admin.test.com
I am using a WAMP server with virtual host enabled.
here's my httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin admin#test.com
DocumentRoot "c:\wamp\www\test"
ServerName test.com
ServerAlias www.test.com
ErrorLog "C:\wamp\www\test\logs\error.log"
CustomLog "C:\wamp\www\test\logs\access.log" common
<Directory "c:/wamp/www/test">
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#test.com
DocumentRoot "C:\wamp\www\test\administrator"
ServerName admin.test.com
ServerAlias www.admin.test.com
ErrorLog "C:\wamp\www\test\logs\error.log"
CustomLog "C:\wamp\www\test\logs\access.log" common
<Directory "c:/wamp/www/test/administrator">
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
test.com works fine, but the admin doesn't. It only displays a white blank page. I also noticed that the redirection works in admin since the page title loads the admin page title.
I'm using Joomla! 3.4.4 Stable, and WAMP Server with Apache/2.4.9 and PHP 5.5.12.
In your configuration.php file under your Joomla website, set $error_reporting to "maximum". This will show you what the error really is and will give you pinpoints on how to fix it.

vHosting on Apache2.2 won't work properly

So, I set up two virtual hosts on my apache and now, I can't access the server via localhost anymore.
Here's my vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#serv.net.local
DocumentRoot "W:/www"
<Directory "W:/www/">
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
ServerName serv.net.local
ErrorLog "logs/serv.net.local-error.log"
CustomLog "logs/serv.net.local-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#symfony.net.local
DocumentRoot "W:/www/symfony/web"
<Directory "W:/www/symfony/web/">
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
ServerName symdev.net.local
ServerAlias symfony.net.local
ErrorLog "logs/symdev.net.local-error.log"
CustomLog "logs/symdev.net.local-access.log" common
</VirtualHost>
All domains are in my hosts-file and are properly resolved. But I can only access the second vHost and get a connection reset error when trying to access localhost or serv.net.local. Same for using 127.0.0.1...
Any ideas whats wrong with this config?
According to discussion in comments, VirtualHost DocumentRoot was not readable because it contained no index, and directory listing was disabled, so fixing it solved the issue.