This site can’t be reached after installing WSL2 and apache2 - windows-10

I updated my WSL1 to WSL2 and install
ubuntu 20.04,
Apache2 and
php8
Now visiting localhost will display the Apache2 Ubuntu Default Page
Next I create a conf file on /etc/apache2/sites-available/items.test.conf containing
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName items.test
ServerAdmin admin#items.test
DocumentRoot /mnt/c/www/path/to/public
<Directory /mnt/c/www/path/to/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
run sudo a2ensite items.test.conf and sudo service apache2 reload. Next open host with notepad with administrator, and added 127.0.0.1 items.test
Visiting the site locally items.test give me this message
This site can’t be reached
What am I missing in this, spend 24hrs tweaking and no luck

After digging another few hours I found the answer, update host file with such a like:
127.0.0.1 test.tld
::1 test.tld
Source: https://github.com/microsoft/WSL/issues/4347

Related

Mod_wsgi daemon mode not reloading web page templates

I cannot reload django templates by touching the wsgi.py script located in my django application root/application name.
The script and project are located under /var/www, so I need sudo to execute touch.
I am running production apache2 server running a django website with mod_wsgi in daemon mode. I can collectstatics and make migrations, access database (without permission issues). I can also change the DEBUG flag in the settings. If I touch wsgi.py, it will put the production site into debug as expected, but the htmls are not loaded. Likewise I can update the static files, collectstatics, or modify the underlying models and see the changes live. Likewise I can use the commented code to retrieve what Daemon mode the swerver is running in. Its only the templates causing an issue. The settings file, wsgi.py, statics and python scripts are responded as expected.
Has anyone got any idea how to debug this?
virtualenv python3.8.12 apache2.4
mod_wsgi compiled for python3.8.12
wsgi.py
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../app/")))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mb.settings')
application = get_wsgi_application()
#def application(environ, start_response):
# status = '200 OK'
# if not environ['mod_wsgi.process_group']:
# output = u'EMBEDDED MODE'
# else:
# output = u'DAEMON MODE'
# response_headers = [('Content-Type', 'text/plain'),
# ('Content-Length', str(len(output)))]
# start_response(status, response_headers)
# return [output.encode('UTF-8')]
apache2 site config
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName app
ServerAdmin webmaster#localhost
ServerName ------removed for posting-----
ServerAlias -----removed for posting------
DocumentRoot /var/www/vhosts/mb
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory /var/www/vhosts/mb>
Order allow,deny
Allow from all
Require all granted
</Directory>
Alias /static /var/www/vhosts/mb/static
<Directory /var/www/vhosts/mb/static>
Require all granted
</Directory>
<Directory /var/www/vhosts/mb/mb>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess mb python-path=/var/www/vhosts/mb python-home=/var/www/vhosts/mb/pyenv
WSGIProcessGroup mb
WSGIScriptAlias / /var/www/vhosts/mb/mb/wsgi.py
WSGIApplicationGroup %{GLOBAL}
</VirtualHost>
For some reason, I did an scp copy into the directory with a new html and not a git push. The result? I used a recursive copy on scp with the -r flag. This created a subdirectory automatically. It confused the daemon. Removing this subdirectory fixed the issue, and touch worked fine.

mkcert certificate not works on local ip adress

I'm trying to convert my app to PWA and I need to use https on localhost on my raspberrypi 4 and can be reached using 192.168.0.2 on LAN
Certificate seems to be not valid and I don't understand what I'm missing.
All command are executed as root user and all steps are from GitHub official page
mkcert -install
mkcert 192.168.80.2
Using the local CA at "/root/.local/share/mkcert" ✨
Created a new certificate valid for the following names �
- "192.168.0.2"
The certificate is at "./192.168.0.2.pem" and the key at "./192.168.0.2-key.pem" ✅
mv 192.168.0.2-key.pem /etc/apache2/ssl/192.168.0.2-key.pem
mv 192.168.0.2.pem /etc/apache2/ssl/192.168.0.2.pem
ls -l /etc/apache2/sites-enabled
lrwxrwxrwx 1 root root 29 Jul 21 16:34 hiker.conf -> ../sites-available/hiker.conf
sites-available/hiker.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName 192.168.0.2
ServerAdmin webmaster#localhost
DocumentRoot /var/www
Alias /hiker /var/www/hiker/public
<Directory /var/www/hiker/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName 192.168.0.2
ServerAdmin webmaster#localsite.test
DocumentRoot /var/www
Alias /hiker /var/www/hiker/public
<Directory /var/www/hiker/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/localsite-error.log
CustomLog ${APACHE_LOG_DIR}/localsite-access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/192.168.0.2.pem
SSLCertificateKeyFile /etc/apache2/ssl/192.168.0.2-key.pem
</VirtualHost>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
apachectl configtest
Syntax OK
service apache2 restart
I found the solution thank to #SteffenUllrich.
I order to import CA into windows 10 follow steps described here "make-computer-trust-certificate-authority"
I can now make tests to convert my app to PWA

one sub domain is working but simliar content subdmain in different IP is not working

Contents are similar in both subdomains. But one domain is working but the other is not working.
Apache host files.
merchant.clouspos.lk (This is working)
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerName merchant.cloudpos.lk
ServerAlias merchant.cloudpos.lk
ServerAdmin webmaster#et.lk
RedirectMatch 301 /ipgresponse_dfecVfBuvsdRkY24(.*) /main.html#/paymentprocessing$1
DocumentRoot /var/www/merchant/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
merchant2.cloudpos.lk (This is redirct to different site)
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerName merchant2.cloudpos.lk
ServerAlias merchant2.cloudpos.lk
ServerAdmin webmaster#et.lk
RedirectMatch 301 /ipgresponse_dfecVfBuvsdRkY24(.*) /main.html#/paymentprocessing$1
DocumentRoot /var/www/merchant2/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
Please provide a solution for this issue? Source code is same in both subdomains.

Browser try to download .pl file instead of executing it - apache2, perl cgi scripts, ubuntu

My ubuntu version is 15.04.
I followed the steps for configuring the server:
sudo apt-get install apache2
sudo apt-get install libapache2-mod-perl2
sudo apt-get install perl-debug
sudo apt-get install libapache2-mod-perl2-dev
sudo apt-get install libapache2-request-perl libdatetime-perl
mkdir /var/www/cgi-bin
nano perltest.pl
#!/usr/bin/perl -w
print "Content-type: test/html\r\n\r\n";
print "Hello there!<br/>\nJust Testing. <br/>\n";
for ($i=0; $i<10;$i++)
{
print $i."<br/>";
}
chmod a+x perltest.pl
Edit /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
< Files ~ "\.(pl|cgi)$">
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
Options +ExecCGI
PerlSendHeader On
< /Files>
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
< Directory /var/www/cgi-bin/>
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
AddHandler cgi-script cgi pl
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
/etc/apache2/sites-available/default-ssl.conf file is here(line 5-11)
/etc/apache2/sites-enabled/000-default.conf file is here(line 12-37)
Add lines to nano /etc/apache2/apache2.conf file is here(line- (54-78))
In browser, hit http://127.0.0.1/cgi-bin/perltest.pl
But, the browser downloads the files.
I am unable to understand the problems. Please help.
print "Content-type: test/html\r\n\r\n";
^
Here is your problem
should be print "Content-type: text/html\r\n\r\n";
goto root and restart the apache server in your machine by the following command
/etc/init.d/apache2 restart

Change document root folder of Apache web server on Linux

My PC is windows 8.1 and Linux mint 16 dual boot pc.I created Local web server on Linux Mint.It's document root is "/var/www".But all my projects are located on a NTFS partion which i mount to linux and use(/media/randika/HardDisk/Works/Lab).I need to make a symbolic link to projects folder or change document root of Apache server.How can i do it?`
My 000-default.conf file located in sites-available folder
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Just change inside your Virtualhost
DocumentRoot /var/www
to
DocumentRoot /media/randika/HardDisk/Works/Lab
and add the rights on the new directory
<Directory "/media/randika/HardDisk/Works/Lab">
Order Allow,Deny
Allow from all
Options Indexes
AllowOverride AuthConfig
</Directory>
And restart Apache for reload the configuration
Fixed it.when mounting a partition, linux automatically sets permissions for all files and directories in that partition.Permissions cannot change after mounted.Therefore Unmounted the partition,changed umask value to 022 in etc/fstab and created a symbolic link.Everything works fine.

Resources