1

This question already has an answer here:

I'm running CentOS 6.3 and Apache 2.2.15.

I'm using the defaults setup for apache. The files I'm serving are in

/var/www/html

Here are two of them

[root@gisele html]# ls -l *-production-1.0.6.pdf 
-r--r--r--. 1 root root 171769 Jan  1 21:12 copy-installation-production-1.0.6.pdf
-r--r--r--. 1 root root 171769 Jan  1 20:59 installation-production-1.0.6.pdf

The copy file is a file created by doing

cp installation-production-1.0.6.pdf copy-installation-production-1.0.6.pdf

Through a virtual host mapping I'm accessing these documents.

copy-installation-production-1.0.6.pdf will serve. installation-production-1.0.6.pdf returns a 403 forbidden.

The only difference, is that the original file was copied onto the server from another machine.

Any idea why this original file will not serve but the copy will?

marked as duplicate by Jenny D, Dennis Kaarsemaker, Michael Hampton Jan 4 '14 at 0:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Well, disabling SELinux it's just a temporary workaround, not a solution. We don't wan't to make Dan Walsh cry ;)

Try one of these options:

chcon --reference=/var/www/html/FileThatCanBeServed /var/www/html/FileWithError403

or

chcon -R --reference=/var/www/html /var/www/html/

or

chcon -R -t httpd_sys_content_t /var/www/html/

Always check the SELinux context of the files that are accessible with ls -lZ, then use chcon with the --reference option to copy the context to other files.

  • 2
    I'm glad he's crying! :) Some of the code of SELinux contributed by the NSA. – Will Jan 2 '14 at 2:48
  • Haha.. yeah you've got a good point there! :) – Gabriel Talavera Jan 2 '14 at 2:52
2

Gah, SELinux. Same probalem as this question: Apache serves some files, others get 403

Turn off SELinux being the solution.

http://www.crypt.gen.nz/selinux/disable_selinux.html

There should be a prompt in the CentOS installation

Is this machine primarily a 
Server (1) / Desktop (2)
1/2...? 1

Would you like to run into bizarre errors later on?
Y/N...? y

Installing SELinux.

Not the answer you're looking for? Browse other questions tagged or ask your own question.