百度云虚拟主机BCH自定义配置注解
前几天使用百度云BCH虚拟主机搭建了thinkphp5.1框架,今天想上传一个模板,上传后发现一个问题,就是网站的所有字体及图标都不显示了,在本地环境下是正常显示的,那么问题肯定出在配置上面。
我们之前上传的配置文件如下:
location / { root /home/bae/app/public; if (-e $document_root/index.php) { ## 获取正则匹配中的数据,wwwxxx.com/test/ 实际访问路径问 www.xxx.com/index.php/test rewrite ^/(.*)$ /index.php/$1?$query_string last; } return 404; } ## php配置 location ~ [^/]\.php(/|$){ root /home/bae/app/public; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; fastcgi_intercept_errors on; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REQUEST_SCHEME $scheme; fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ { root /home/bae/app/public; expires 30d; access_log off; } location ~ .*\.(js|css)?$ { root /home/bae/app/public; expires 7d; access_log off; } location ~ /\.ht { root /home/bae/app/public; deny all; } ## 禁止敏感文件的直接访问 location ~* \.(inc|bak|sql|lua|so|ini|conf)$ { deny all; }
关于此配置不做过多的说明了,就是常见的配置方法,我们的字体文件后缀格式为woff2、eot、svg、ttf、woff等,那么我们将其放置到静态文件配置中,将配置更改如下:
location / { root /home/bae/app/public; if (-e $document_root/index.php) { ## 获取正则匹配中的数据,wwwxxx.com/test/ 实际访问路径问 www.xxx.com/index.php/test rewrite ^/(.*)$ /index.php/$1?$query_string last; } return 404; } ## php配置 location ~ [^/]\.php(/|$){ root /home/bae/app/public; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; fastcgi_intercept_errors on; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REQUEST_SCHEME $scheme; fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ { root /home/bae/app/public; expires 30d; access_log off; } location ~ .*\.(js|css|woff2|eot|svg|ttf|woff)?$ { root /home/bae/app/public; expires 7d; access_log off; } location ~ /\.ht { root /home/bae/app/public; deny all; } ## 禁止敏感文件的直接访问 location ~* \.(inc|bak|sql|lua|so|ini|conf)$ { deny all; }
即可正常访问文字图标等静态资源了。其他后缀的文件如果无法访问,可同理进行更改。