Nginx – CentOs 7 Nginx (13: Permission denied) while loading font file from css

centos7file-permissionsfontnginx

I have an nginx webserver with bootstrap js framework. I am trying to get the css to be able to load the font files. Although i get error 403 when the browser is trying to access the font files.

I have looked around serverfault for those that have similar issues although i was unsuccessful in applying their solutions. ex: "How can I make nginx support @font-face formats and allow access-control-allow-origin?"

Below is my error and my server configuration:

Error:

2016/01/07 10:30:10 [error] 20770#0: *26 open() "/usr/share/nginx/html/fonts/glyphicons-halflings-regular.ttf" failed (13: Permission denied), client: 0.0.0.0, server: localhost, request: "GET /fonts/glyphicons-halflings-regular.ttf HTTP/1.1", host: "localhost", referrer: "http://localhost/css/bootstrap.min.css"

/etc/nginx/conf.d/default.conf:

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;

        if ($request_filename ~* ^.*?/([^/]*?)$)
            {
                set $filename $1;
            }

        if ($filename ~* ^.*?\.(eot)|(ttf)|(woff)$){
                add_header Access-Control-Allow-Origin *;
           }
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    location ~ \.php$ {
        root           /usr/share/nginx/html;
        try_files $uri =404;
        fastcgi_pass   unix:/var/run/php-fpm/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }


    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
     #
    location ~ /\.ht {
        deny  all;
    }
}

/etc/nginx/mime.types:

application/vnd.ms-fontobject         eot;
    application/font-sfnt                 otf ttf;
    application/font-woff                 woff;
    application/font-woff2                woff2;

systemctl restart nginx.service

Best Answer

That's nginx failing to open the file (as opposed to nginx denying access by itself), make sure nginx's user is allowed to read glyphicons-halflings.ttf