apache downloads text file instead of displaying on browser. This happens only if the owner of the file is not the apache user.
I'm trying to open the alis /log in apache:
Alias /log "/home/log/"
<Directory /home/log/>
Options Indexes FollowSymLinks MultiViews
Order allow,deny
Allow from all
AllowOverride None
</Directory>
It could be worth mentioning that file extensions are .log example: filename.log
needed to add this line in httpd.conf
AddType text/plain .js .sh .txt .log
I tackled this before but failed because I forgot to add the .log
from this link:
https://web.archive.org/web/20171224215131/https://marcel.zurreck.com/nginx-apache-force-the-browser-to-show-a-file-instead-of-downloading
Related
I'm running httpd on fedora server 35 and want to use it to serve files on my local network. It works fine for files stored under the /var/www/html directory directly (e.g. /var/www/html/videos/video.mp4 can be accessed with http://IP/videos/video.mp4 on any local device).
I want to serve files stored in other locations in the file system. My plan was to create symbolic links to those locations. When I do that, I run into forbidden errors when trying to access the files (e.g. A video file /files/videos/video.mp4 linked with a sym link /var/www/html/videos-link -> /files/videos/ so that I would (theoretically) access it with http://IP/videos-link/video.mp4
I can navigate to http://IP/videos-link fine (an Index of DIRECTORY page, but no files are listed), but trying to access the file (http://IP/videos-link/video.mp4) gives me 403 forbidden.
My config (/etc/httpd/conf/httpd.conf) looks like this (it's a bit messy since I've been trying to fix this myself):
<Directory />
Options FollowSymLinks Indexes
AllowOverride All
Require all granted
</Directory>
...
<Directory "/var/www">
Options +FollowSymLinks +Indexes
AllowOverride All
Require all granted
</Directory>
...
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
...
<Directory "/files/videos">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
In attempts to make it work I've made sure the sym link and all the directories have the same owner and that their all 777 so ownership/read perms shouldn't be an issue. Would greatly appreciate some help, thanks.
My issue was with SELinux. To get it working immediately I was able to set SELinux to permissive mode with
# setenforce 0
That refreshes on boot and is probably insecure, so the permanent fix (to just let httpd through) would be:
# semanage permissive -a httpd_t
More details on SELinux in Fedora can be found here: https://docs.fedoraproject.org/en-US/quick-docs/getting-started-with-selinux/
I want to make log files download automatically when I connect to http://myhost/download.
I know I have to deal with the .htaccess file and httpd.conf file, but the Forbidden screen keeps coming up.
Log files in download directory.
httpd.conf
Alias /download /etc/httpd/download
<Directory "/etc/httpd/download">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
.htaccess
AddType application/force-download *.log
The server I'm working on is Amazon Linux 2.
If you know what's lacking or wrong, please share that knowledge to me.
On our Apache server no users can upload the .htaccess file. They get a critical error when upload just this file via FTP. We can upload all other file types just fine. Is there a way I can allow this permission across all my sites?
This was fixed in the end by adding the following lines to the vhost config for the site:
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
If I use the SetHandler default-handler option, I can no longer have an index for all the files in the directory. That is, Options +Indexes breaks. Is there a way to fix this or is there an alternate way to listing files in a directory using Apache?
You don't need an index for all the files in the directory. Are you trying to do
/index.php
or run some other script and when you do
/
you want the index of the directory? To see a list of files in a directory use this
<Directory /this/is/the/list/directory>
Options +Indexes
</Directory>
Have a look here...
https://wiki.apache.org/httpd/DirectoryListings
This seems to work:
<Directory /srv/html/test>
<Files ?*>
SetHandler default-handler
</Files>
</Directory>
It should set the default handler on all files with a filename of 1 character or longer. Autoindexing still works (if you have that configured, that is).
I have a directory structure like the following for a website on Ubuntu 14.04, running apache 2.4.7:
/websites/mywebsite/index.htm
/websites/mywebsite/private.htm
/websites/myqwbsite/folder/privatefile.ext
/websites/mywebsite/folder/subfolder/publicfile.ext
In the Apache config for the site, I have
<Directory /websites/mywebsite/>
AllowOverride Limit
Require all granted
</Directory>
I want to use .htaccess files in the site folder such that the private.htm and privatefile.ext files are Require all denied but everything else is granted.
I tried the following two .htaccess files:
/websites/mywebsite/.htaccess:
<FilesMatch (private.*.htm)$>
Require all denied
</FilesMatch>
/websites/mywebsite/folder/.htaccess:
Require all denied
/websites/mywebsite/folder/subfolder/.htaccess:
Require all granted
However, apache gives a 500 - "Require not allowed here" for /websites/mywebsite/.htaccess
How can I make what I want happen with apache 2.4-compatible configuration (ie I do not want to load mod_access_compat and use the old style config)?
In the apache config for the site, you have to extend AllowOverride properties. Add: FileInfo and AuthConfig. Or set "AllowOverride All"
I had same problem, fixed with this config :
<Directory /websites/mywebsite/>
Options +FollowSymLinks +SymLinksIfOwnerMatch
AllowOverride FileInfo AuthConfig
</Directory>