Nginx

CentOs 7 Nginx (13: Permission denied) 同時從 css 載入字型檔

  • April 7, 2016

我有一個帶有引導 js 框架的 nginx 網路伺服器。我試圖讓 css 能夠載入字型檔。雖然當瀏覽器嘗試訪問字型檔時出現錯誤 403。

儘管我未能成功應用他們的解決方案,但我已經查看了那些有類似問題的伺服器故障。例如:“如何讓 nginx 支持@font-face 格式並允許訪問控制允許來源?

以下是我的錯誤和我的伺服器配置:

錯誤:

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 重啟 nginx.service

那是 nginx 無法打開文件(而不是 nginx 自己拒絕訪問),請確保允許 nginx 的使用者讀取 glyphicons-halflings.ttf

引用自:https://serverfault.com/questions/768818