pagekit 出现 Access Denied 提示及 svg 图片 404 解决办法

当前位置: 首页 » 记录 » pagekit 出现 Access Denied 提示及 svg 图片 404 解决办法

分类: 记录 3288阅读阅读模式

在 Linux 服务器中的 Nginx 装好以后会出现 Access Denied ,则需要开启 http 的重写模式。

 

修改配置:

在当前的网站的 Nginx 配置文件中添加或修改为下面的代码

提示:一般配置地址为 /usr/local/nginx/conf/vhost/example.conf 。

  1. location ~ \.php$ {
  2. try_files $uri =404;
  3. #fastcgi_pass unix:/var/run/php-fpm.sock;
  4. ### this 'fastcgi_pass' is you php.sock location, please confirm that it is correct; ###
  5. fastcgi_index index.php;
  6. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  7. include fastcgi_params;
  8. fastcgi_param HTTP_MOD_REWRITE On;
  9. }

如果安装页面提示 404 错误,则是没有开启伪静态规则。需要在其中加上下面代码

  1. location / {
  2.   try_files $uri $uri/ /index.php?$query_string;
  3. }

 

额外的:

为了防止 db 文件及一些不允许访问的文件被访问而泄露,需要返回 403 错误处理。

  1. # Deny access to sensitive folders
  2. location ~* /(app|packages|storage|tmp)/.*$ {
  3. return 403;
  4. }
  5. # Deny access to files with the following extensions
  6. location ~* \.(db|json|lock|dist|md)$ {
  7. return 403;
  8. }
  9. # Deny access to following files
  10. location ~ /(config.php|pagekit|composer.lock|composer.json|LICENSE|\.htaccess) {
  11. return 403;
  12. }

 

图片 404 处理:

网站大部分用 svg 做图标。但是如果不添加缓存处理,网站会出现图片 404。

需要查找类似代码,修改为下方代码,即 (?:ico|css|js|gif|jpe?g|png|ttf|woff|svg|flv|swf) 里面的后缀名

  1. location ~* \.(?:ico|css|js|gif|jpe?g|png|ttf|woff|svg|flv|swf)$ {
  2. access_log off;
  3. expires 30d;
  4. add_header Pragma public;
  5. add_header Cache-Control "public, mustrevalidate, proxy-revalidate";
  6. }

 

完毕!

 

 

相关文章

评论已关闭。