3

I recently moved my CentOS 7 machine from an Apache web server to an nginx web server, and I'm still working out various issues as I learn the in's and out's of nginx. One issue I have stumbled upon is that text files, such as robots.txt, appear to be unaccessible in my public web root directory.

My server block configuration is as follows:

server {
    listen       80;
    server_name  example.com;
    root         /var/www/example.com/public_html;
    index        index.php;
    access_log   /var/www/example.com/logs/example.com_access.log;
    error_log    /var/www/example.com/logs/example.com_error.log error;

    location / {
        index index.php index.html;
    }

    location /reports {
        autoindex on;
    }

    location ~ \.php$ {
        try_files          $uri =404;
        fastcgi_pass       unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_param      SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include            fastcgi_params;
    }

    error_page 404 /var/www/html/404.html;
    error_page 500 502 503 504 /var/www/html/50x.html;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }

    location /robots.txt {
        #access_log off;
        #log_not_found off;
    }

    location ~ /\.ht {
        deny all;
    }
}

I am confused about why text files would be inaccessible. I figured this was a problem with me using PHP, but I couldn't determine what might be blocking access to the file.

I also can't check my log files (yet) because this server block doesn't seem to be writing to my logs, but that's in another question.

What could be going on here?

J.W.F.
  • 338
  • 2
  • 4
  • 16
  • 2
    Deleted answer because it didn't answer your question. Is the mime.types file included in the http block? – Aaron Mason Nov 12 '15 at 04:58
  • @AaronMason I don't believe so, as far as I know I haven't specified anything about that nor do I have any files (as far as I know) that are mime.types. – J.W.F. Nov 12 '15 at 13:51
  • Did you check SELinux settings? – warren Nov 16 '15 at 20:36
  • 1
    @warren I did, I had to move my nginx server blocks to `/var/www/` in order to get SELinux to (more easily) recognize them as web server directories. This was an issue in the past, but as far as I know, SELinux should be labeling the directory correctly. – J.W.F. Nov 17 '15 at 13:57

1 Answers1

0

I had this issue and I restarted nginx and the problem was solved. No idea what caused it as my other domain's .txt files were working.

service nginx restart;

Jack
  • 149
  • 1
  • 5