Score:0

Allow only certain files in Apache

ne flag

The application I built with the django runs on the linux server. As a result of one process I have done in this app, the file.txt is created in this directory: /home/user/app/media/file.txt

My goal is to access this created file from my own machine where the program is running.(I use the app at macOsx). When I typed IP:/home/user/app/media/file.txt on browser, I cannot access texts in file. What should I do? Thanks in advance.

Note: I inserted below code to conf. file in /etc/apache2/.conf but no hope.

<Directory /home/user/app/media>
   <Files file.txt>
       Require all granted
   </Files>
 </Directory>
in flag
If the directory is already set as `/home/user/app/media`, then you do not need to put this in your URL. You can use `{IP}/file.txt`. However, depending on which OS you're using, there may be some additional settings you need to configure in order to allow Apache to read from `/home`. By default, Apache is limited to `/var/www`.
göktuğ Inal avatar
ne flag
You were right! It works exactly like that {IP}/media/file.txt
Score:1
uz flag

The URL you are providing looks a bit strange with the ":" after "IP". Furthermore, you should setup a virtual host using you own URL (e.g. "myapp.local") and put this in the /etc/hosts file (127.0.0.1 myapp.local).

Please find the config for an apache virtual host below. place it in /etc/apache2/sites-available/myapp.conf and activate using sudo a2ensite myapp.conf.

Please note the ServerName: this is the URL you should type in the browser.

<VirtualHost *:80>
# This config will serve the built version of the production version of the crisisgame.molema.org website for local use with local parameters
    ServerAdmin webmaster@localhost
    ServerName myapp.local

    DocumentRoot /home/user/app
    DirectoryIndex index.html

    
    <Directory /home/user/app/>
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.myapp.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.myapp.log combined

</VirtualHost>

Then edit you /etc/hosts and add:

  127.0.0.1 myapp.local

Then restart the Apache2 Service using sudo service apache2 restart.

If restarting the service yields an error, then follow the procedure below to find the error. This will elevate you to root-privileged new shell, set Apache's environment variables and then ask Apache to run a check (-S parameter)

 martin@debian:~$ sudo -i
 [Password]: 
 root@debian:~# cd /etc/apache2
 root@debian:~# . ./envvars
 root@debian:~# apache2 -S
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)

Notice the way envvars is executed: dot-space-dot-slash prefixed. This means that if the script envvars modifies environment variables their values will be available in the current shell (the first . represents the current shell). See also Bash Reference Manual, chapter 3.7.4.

The first error usually is no problem. If this report shows other errors, go fix them. Possibly lookup the configs for Apache2 here

Go to your browser and type http://myapp.local/media/file.txt.

Good luck!

Greetings Martin

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.