0

I made the virtual host setup in Ubuntu 20.04 for accessing virtually to my web projects. I have followed the necessary steps properly, but since I wanted to work more portable and access my web projects from outside rather than default document root, so I set my own media device path (/media/akin/7114-BB32/htdocs/) instead of the default document root (/var/www/html/).

But when I wanted to access the my domain (htdocs.com) from the browser, it did not work, I could not view my own index page. It opened the index of a different web page. I could not find exactly what I was doing wrong or missing.

What should I do for it?

And here is my domain.conf(htdocs.conf):

<VirtualHost *:80>  
    
    ServerAdmin webmaster@htdocs.com
    ServerName www.htdocs.com
    ServerAlias www.htdocs.com
    DocumentRoot /media/akin/7114-BB32/htdocs
    
    <Directory /media/akin/7114-BB32/htdocs>
        Options Indexes FollowSymLinks  
        AllowOverride all
        Require all granted
    </Directory>    

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    
</VirtualHost>

apache2.conf:

PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf


<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    Options +MultiViews
    AllowOverride All
    Require all granted
</Directory>

<Directory /media/akin/7114-BB32/htdocs/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>


AccessFileName .htaccess


<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

Also my document root permission list:

ls -la /media/akin/7114-BB32/htdocs

drwxr-xr-x  2 akin akin 8192 May 17 22:38 .
drwxr-xr-x 11 akin akin 8192 Jan  1  1970 ..
-rw-r--r--  1 akin akin 1319 May 17 22:38 index.html
AKIN CAN
  • 3
  • 2

1 Answers1

0

Since you have the FollowSymLinks option enabled, the cleanest way to do this would be adding the symlink to your web root. That way you wouldn't even need to mess around the apache2.conf.

ln -s /media/akin/7114-BB32/htdocs /var/www/htdocs

and point your virtual host to /var/www/htdocs also check if apache has all needed permissions (IIRC it needs "execute" permissions to open something)

EDIT: in your apache2.conf i don't see if you are including optional (virtual host) configs. it should look something like this IncludeOptional sites-enabled/*.conf (near the bottom of the file) so if you don't have it chances are apache can't even register that virtual host.

Maxoholic
  • 170
  • 6
  • It works! Thank you. But permissions needed to open my files. It shows 403 Forbidden. I'm still trying to give permissions to apache. – AKIN CAN May 17 '21 at 19:32
  • Update your question with the output of `ls -la ` command in that directory so we can see what you need – Maxoholic May 17 '21 at 19:35
  • Sorry, I did not fully understand what to do. I tried this: `ls -la /media/akin/7114-BB32/htdocs` and output was showing the files are writable, readable... – AKIN CAN May 17 '21 at 19:49
  • That is exactly what we need, just edit your question and paste the whole output of that `ls` command inside Or you can check it yourself, file you want to open needs to have "x" permission set for apache – Maxoholic May 17 '21 at 19:54
  • Do `chmod o+x /media/akin/7114-BB32/htdocs/index.html` with that apache should be able to open index.html – Maxoholic May 17 '21 at 20:00
  • Normally this should work but why did not give the permission. I even tried it with sudo. – AKIN CAN May 17 '21 at 20:04
  • Seeing as this is inside /media folder I'll assume that it's some kind of removable device which is formatted as either ntfs or fat system (chmod will only work on linux filesystems like ext4) If i'm right you can consult this page where that question is already answered https://askubuntu.com/questions/11840/how-do-i-use-chmod-on-an-ntfs-or-fat32-partition – Maxoholic May 17 '21 at 20:13
  • Yes the reason for this is now clear. Thank you again for your answer and efforts @Maxoholic. Your answer for this question works and also permission problem solutions works too. – AKIN CAN May 17 '21 at 20:16