How can I make an area of a website password protected through Apache? - html

I have been working on this for a while, and I am trying to use .htaccess and .htpasswd. Here is what I have done:
Performed with Apache using Raspberry Pi 3B+ with DietPi installed.
I created a new .htpasswd file and proceeded to enter password that I wanted.
Next, I redirected to /etc/apache2/sites-enabled/ where I edited 000-default.conf and changed the line of code:
<VirtualHost *80>
ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/etc/"
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^https://%{SERVER_NAME%{REQUEST_URI} [END,Ne,R=permanent]
</VirtualHost>
Everything here is the same, except replace "example" with my domain.
This did not affect my site, so I redirected to /etc/apache2/ where I edited apache2.conf and added the line of code:
<Directory /var/www/etc/>
DirectoryIndex index.php index.html
Options Indexes FollowSymLinks
AllowOverride None
Require all denied
</Directory>
Once again, everything here is the same. etc is the file that I want to password-protect. This made the page that I wanted to protect completely inaccessible, and when I changed AllowOverride and Require all it just made the page completely open. How can I make it so that a password is prompted when you try to access the directory?

Related

"Your data directory and your files are probably accessible from the Internet. The .htaccess file is not working." - Nextcloud

I recognized that my nextcloud installation has following problem:
“Your data directory and your files are probably accessible from the Internet. The .htaccess file is not working. We strongly suggest that you configure your web server in a way that the data directory is no longer accessible or you move the data directory outside the web server document root.”
My apache2 config of the directory with the nextcloud installation looks like this:
<VirtualHost *:80>
ServerAdmin emailadresse#email.org
ServerName cloud.domain.yt
ServerAlias cloud.domain.yt
DocumentRoot /var/www/cloud.domain.yt
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /root/cloudflare/domain.yt.pem
SSLCertificateKeyFile /root/cloudflare/domain.yt.key
</VirtualHost>
<VirtualHost *:443>
ServerName cloud.domain.yt
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
</IfModule>
</VirtualHost>
<Directory /var/www/cloud.domain.yt/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
SetEnv HOME /var/www/cloud.domain.yt
SetEnv HTTP_HOME /var/www/cloud.domain.yt
<IfModule mod_dav.c>
Dav off
</IfModule>
</Directory>
My .htaccess file (in the data directory looks like this:
# Generated by Nextcloud on 2021-11-08 19:38:35
# Section for Apache 2.4 to 2.6
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule mod_access_compat.c>
Order Allow,Deny
Deny from all
Satisfy All
</IfModule>
# Section for Apache 2.2
<IfModule !mod_authz_core.c>
<IfModule !mod_access_compat.c>
<IfModule mod_authz_host.c>
Order Allow,Deny
Deny from all
</IfModule>
Satisfy All
</IfModule>
</IfModule>
# Section for Apache 2.2 to 2.6
<IfModule mod_autoindex.c>
IndexIgnore *
</IfModule>
It should work perfectly fine. But it doesnt. I also installed all required apache2 addons.
I also wrote with someone on a github post. The user said it would probably be better to ask on websites like this one.
Most other informations are already on the github post (about 9 hours old right now)
https://github.com/nextcloud/server/issues/6449
How can I fix this?

Error code 403 when using WAMP for custom website

When attempting to access a website i am attempting to host on my pc using WAMP i get the typical error code 403 forbidden. I have edited the apache config to allow all etc but still seem to get it, however i can see localhost and phpadmin from 127.0.0.1
Any other suggestions? i can attach my apache config or put it in a pastebin if needed
For reference im running Win10(64x) with WAMP Server 3.0.6 (64x)
I have followed multiple tutorials from youtube and stackoverflow but cannot seem to get it to work as most use commands given are from linux such as 'chmd' (i have used linux before therefor understand what this means but cant work out how to do the same thing via windows)
Try making virtual host and give access to all local user. Make sure you give access to
file -------> httpd.conf
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
#onlineoffline tag - don't remove
Require local
Require ip 192.168.0
</Directory>
Edit httpd-vhosts.conf As like:
file ------> httpd-vhosts.conf
# Virtual Hosts
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName smarthome
DocumentRoot "c:/wamp64/www/smarthome"
<Directory "c:/wamp64/www/smarthome/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

rewrite localhost to www directory

I had a lot of difficulties getting a domain of mine to point to a folder in my Wamp /www directory.
However, I'm now wanting to work on getting another domain working, but before that I'd like to work on the domain under localhost and edit it through there.
But, whenever I go to localhost or the Ip of the server on a browser, it goes to my domain.
I only want to go to that domain when I type the domains name, not when I type localhost on that machine or the IP on a different machine.
TL:Dr;
I want mywebsite.com > /www/mywebsite (this has already been done)
I want localhost/ > /www (main folder)
Windows Server with WAMP
Here's my current htaccess to get the domain working with the folder (probably not an efficient way) Removed thanks to RiggsFolly
RewriteEngine On
RewriteCond %{HTTP_HOST} (?:www\.)?mywebsite\.com [NC]
RewriteCond %{REQUEST_URI} !^/mywebsite
RewriteRule ^(.*)$ /mywebsite/$1 [L]
RewriteRule ^(.*)$ http://mywebsite.comk/$1 [L,R=301]
After adding Virtual hosts
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin info#mywebsite.com
DocumentRoot "c:/wamp/www/mywebsite"
ServerName mywebsite.com
ServerAlias www.mywebsite.com
ErrorLog "logs/mywebsite-error.log"
CustomLog "logs/mywebsite-access.log" common
</VirtualHost>
Still not working.
localhost will load mywebsite.com (name changed for privacy). I want localhost to load the main directory not the mywebsite sub-directory!

Creating sub domain on webmin

Can anybody help me in creating subdoain through webmin. I want to create subdomain like test.xxxxx.com for this I tried with several reference site but no luck.
exp.
http://www.trickylinux.net/add-domain-virtualminwebmin.html
http://codeboxlabs.com/add-subdomain-webmin-linux/
My current httpd.conf look like:
<VirtualHost *:80>
SSLEngine off
DocumentRoot /var/www/html/******/web
DirectoryIndex index.php
<Directory "/var/www/html/*****/web">
AllowOverride All
Allow from All
</Directory>
ServerName www.******.com
ServerAlias ftp.*****.com
SSLEngine off
SSLVerifyClient optional
</VirtualHost>
Please help me to solve this issue.
I know its been a year and you must have found a path already but its for the future reference.
Just add another host:
<VirtualHost *:80>
DocumentRoot /var/www/html/******/subdomain
DirectoryIndex index.php
<Directory "/var/www/html/*****/subdomain">
AllowOverride All
Allow from All
</Directory>
ServerName www.subdomain.******.com
ServerAlias subdomain.******.com
SSLEngine off
SSLVerifyClient optional
</VirtualHost>
Of course restarting apache is needed in order to make it read the new VHost
What you need to do next is add an A record in you domain registrar (i.e, Godaddy). Record name will be your "subdomain" and it'll point to your server address:
A-----------------> # --------------------> ******.com
A-----------------> ******.com------------> ******.com
A-----------------> subdomian.******.com--> ******.com

Server Side Includes

I got the following error message in the Apache log:
unable to include potential exec "header.html" in parsed file /Users/sikusiku/Sites/ss-git/homepage.shtml
I basically tried to include header.html from homepage.shtml. I used the very basic directive in homepage.html (both header.html and homepage.shtml are located in the document root):
<!--#include virtual="header.html" -->
I think I have properly turned on the SSI in my httpd.conf:
Options Indexes FollowSymLinks ExecCGI Includes
...
AddType text/html .shtml
...
# XBitHack doesn't have anything to do with this, but I added it anyway.
XBitHack on
Did I miss anything? Does the included file i.e. header.html need to be configured differently?
I just fixed this problem myself on ubuntu sever 11.10 with apache2.
my /etc/apache2/sites-available/default file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I changed AllowOverride None to All in /var/www directory directive.
my .htaccess file in /var/www/.htaccess:
Options +Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
finally i made sure that include.load was in the mods-enabled folder this is to load the mod_includes.so module.
sudo ln -s /etc/apache2/mods-available/include.load /etc/apache2/mods-enabled/include.load
That creates a symbolic link to the include.load in mods-available.
finally restart apache
sudo service apache2 restart
That made it work for me, hope you get it working as well.
--
Thomas