在 Linux 服务器中的 Nginx 装好以后会出现 Access Denied ,则需要开启 http 的重写模式。
修改配置:
在当前的网站的 Nginx 配置文件中添加或修改为下面的代码
提示:一般配置地址为 /usr/local/nginx/conf/vhost/example.conf 。
- location ~ \.php$ {
- try_files $uri =404;
- #fastcgi_pass unix:/var/run/php-fpm.sock;
- ### this 'fastcgi_pass' is you php.sock location, please confirm that it is correct; ###
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- fastcgi_param HTTP_MOD_REWRITE On;
- }
如果安装页面提示 404 错误,则是没有开启伪静态规则。需要在其中加上下面代码
- location / {
- try_files $uri $uri/ /index.php?$query_string;
- }
额外的:
为了防止 db 文件及一些不允许访问的文件被访问而泄露,需要返回 403 错误处理。
- # Deny access to sensitive folders
- location ~* /(app|packages|storage|tmp)/.*$ {
- return 403;
- }
- # Deny access to files with the following extensions
- location ~* \.(db|json|lock|dist|md)$ {
- return 403;
- }
- # Deny access to following files
- location ~ /(config.php|pagekit|composer.lock|composer.json|LICENSE|\.htaccess) {
- return 403;
- }
图片 404 处理:
网站大部分用 svg 做图标。但是如果不添加缓存处理,网站会出现图片 404。
需要查找类似代码,修改为下方代码,即 (?:ico|css|js|gif|jpe?g|png|ttf|woff|svg|flv|swf) 里面的后缀名
- location ~* \.(?:ico|css|js|gif|jpe?g|png|ttf|woff|svg|flv|swf)$ {
- access_log off;
- expires 30d;
- add_header Pragma public;
- add_header Cache-Control "public, mustrevalidate, proxy-revalidate";
- }
完毕!